WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
241416
[meta] IPC encoders could be simplified / sped-up
https://bugs.webkit.org/show_bug.cgi?id=241416
Summary
[meta] IPC encoders could be simplified / sped-up
Jean-Yves Avenard [:jya]
Reported
2022-06-08 06:48:24 PDT
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.
Attachments
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2022-06-08 06:48:44 PDT
<
rdar://problem/94629221
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug