[Webkit-unassigned] [Bug 189231] New: [WTF] Add CompactOptional<T, Traits>

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Sep 2 07:04:57 PDT 2018


https://bugs.webkit.org/show_bug.cgi?id=189231

            Bug ID: 189231
           Summary: [WTF] Add CompactOptional<T, Traits>
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Web Template Framework
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: yusukesuzuki at slowstart.org

std::optional<T> is super nice. We can represent a value with nullopt by using std::optional<T>.
However, as you know, std::optional<T> has storage efficiency problem. It always has a bool indicating that the value is nullopt or not.
If you have a class like,

class A {
    std::optional<MonotonicTime> m_timeA;
    std::optional<MonotonicTime> m_timeB;
    std::optional<MonotonicTime> m_timeC;
};

This class has significant amount of padding between m_timeA / m_timeB, m_timeB / m_timeC due to the above bool.


If we know that MonotonicTime has a value that represents invalid, we can use it instead and save the storage.
This is very similar problem to our HashTable implementation. In our HashTable implementation, we need Deleted / Empty value, which can represent Deleted and Empty values without sacrificing storage efficiency.

So, we should have similar mechanism here. In this patch, we have WTF::CompactOptional<T, Traits>. Traits offers Traits::isEmptyValue() and the way to generate an empty value.
Then, we use this empty value instead of having bool flag. This way, we can make `sizeof(WTF::CompactOptional<T>) == sizeof(T)`.

This idea is inspired from https://github.com/akrzemi1/markable. But we would like to have WTF::CompactOptional<T> here instead of importing it since,

1. We would like to have more integrated interface to std:optional<T>. We would like to have CompactOptional(std::optional<T>) constructor.
2. We would like to integrate existing `isEmptyValue()` mechanism for HashTable easily into CompactOptional<T>.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20180902/b256b42e/attachment.html>


More information about the webkit-unassigned mailing list