[Webkit-unassigned] [Bug 241416] New: [meta] IPC encoders could be simplified / sped-up

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Jun 8 06:48:24 PDT 2022


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

            Bug ID: 241416
           Summary: [meta] IPC encoders could be simplified / sped-up
           Product: WebKit
           Version: Other
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: WebKit2
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: jean-yves.avenard at apple.com
                CC: kkinnunen at apple.com

As seen with bug 241407.

The vast majority of IPC encoders/decoders do the following:

Considering a struct of type T:

```
template<class Encoder> inline void T::encode(T& encoder) const
{
    encoder << param1 << param2 << param3 << param4;
}
```

followed by something like:

```
template<class Decoder> std::optional<T> T::decode(Decoder& decoder)
{
    Param1 param1;
    if (!decoder.decode(param1))
        return { };

    Param1 param2;
    if (!decoder.decode(param2))
        return { };

    Param1 param3;
    if (!decoder.decode(param3))
        return { };

    Param1 param4;
    if (!decoder.decode(param4))
        return { };

    return T { WTFMove(param1), WTFMove(param2), WTFMove(param3), WTFMove(param4) } 
}
```

after every deserialisation a test is performed when it's unlikely to ever be false.

Instead we could do something like:
```
{
    auto param1 = decoder.decode<Param1>();
    auto param2 = decoder.decode<Param2>();
    auto param3 = decoder.decode<Param3>();
    auto param4 = decoder.decode<Param4>();
    if (UNLIKELY(!decoder.isValid()))
        return std::nullopt;

    return T { WTFMove(*param1), WTFMove(*param2), WTFMove(*param3), WTFMove(*param4 };
}
```

it makes the core more readable and allows to only test once for the unlikely case where we have an error.

-- 
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/20220608/b353d966/attachment.htm>


More information about the webkit-unassigned mailing list