RESOLVED FIXED 238608
IPC::Connection should support diverting all messages to a message queue in other thread
https://bugs.webkit.org/show_bug.cgi?id=238608
Summary IPC::Connection should support diverting all messages to a message queue in o...
Kimmo Kinnunen
Reported 2022-03-31 07:54:07 PDT
IPC::Connection should support diverting all messages to a message queue in other thread
Attachments
Patch (23.22 KB, patch)
2022-03-31 08:06 PDT, Kimmo Kinnunen
no flags
Patch (27.23 KB, patch)
2022-03-31 12:10 PDT, Kimmo Kinnunen
no flags
Patch (27.56 KB, patch)
2022-03-31 12:15 PDT, Kimmo Kinnunen
no flags
Patch (27.76 KB, patch)
2022-04-01 05:46 PDT, Kimmo Kinnunen
no flags
For landing (27.80 KB, patch)
2022-04-06 12:36 PDT, Kimmo Kinnunen
no flags
For landing (28.04 KB, patch)
2022-04-06 23:33 PDT, Kimmo Kinnunen
no flags
Kimmo Kinnunen
Comment 1 2022-03-31 08:06:46 PDT
Simon Fraser (smfr)
Comment 2 2022-03-31 12:08:11 PDT
Comment on attachment 456237 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=456237&action=review > Source/WebKit/Platform/IPC/MessageReceiveQueueMap.h:56 > using QueueMap = HashMap<std::pair<uint8_t, uint64_t>, StoreType>; > + using AnyIDQueueMap = HashMap<uint8_t, StoreType>; Why don't these use ReceiverName in place of uint8_t?
Kimmo Kinnunen
Comment 3 2022-03-31 12:10:20 PDT
Kimmo Kinnunen
Comment 4 2022-03-31 12:15:22 PDT
Kimmo Kinnunen
Comment 5 2022-03-31 12:28:34 PDT
(In reply to Simon Fraser (smfr) from comment #2) > Comment on attachment 456237 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=456237&action=review > > > Source/WebKit/Platform/IPC/MessageReceiveQueueMap.h:56 > > using QueueMap = HashMap<std::pair<uint8_t, uint64_t>, StoreType>; > > + using AnyIDQueueMap = HashMap<uint8_t, StoreType>; > > Why don't these use ReceiverName in place of uint8_t? IIRC originally I kept using the code that was there originally. I think it may have something to do with non-valid keys or hashing. I can take a look at that in a separate patch..
Kimmo Kinnunen
Comment 6 2022-04-01 05:46:42 PDT
Chris Dumez
Comment 7 2022-04-01 14:36:14 PDT
Comment on attachment 456354 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=456354&action=review > Source/WebKit/Platform/IPC/Connection.cpp:374 > + ReceiverMatcher receiverMatcher = ReceiverMatcher::createForLegacyAPI(receiverName, destinationID); How is this legacy? > Source/WebKit/Platform/IPC/Connection.cpp:389 > + ReceiverMatcher receiverMatcher = ReceiverMatcher::createForLegacyAPI(receiverName, destinationID); ditto.
Kimmo Kinnunen
Comment 8 2022-04-02 00:24:35 PDT
(In reply to Chris Dumez from comment #7) > Comment on attachment 456354 [details] > > Source/WebKit/Platform/IPC/Connection.cpp:374 > > + ReceiverMatcher receiverMatcher = ReceiverMatcher::createForLegacyAPI(receiverName, destinationID); > > How is this legacy? > > > Source/WebKit/Platform/IPC/Connection.cpp:389 > > + ReceiverMatcher receiverMatcher = ReceiverMatcher::createForLegacyAPI(receiverName, destinationID); > > ditto. Passing zero id to mean any id is legacy and new interfaces should use receiver matcher to explicitly say if the match should apply for zero only or any id.
Simon Fraser (smfr)
Comment 9 2022-04-06 11:55:02 PDT
Comment on attachment 456354 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=456354&action=review >>> Source/WebKit/Platform/IPC/Connection.cpp:374 >>> + ReceiverMatcher receiverMatcher = ReceiverMatcher::createForLegacyAPI(receiverName, destinationID); >> >> How is this legacy? > > Passing zero id to mean any id is legacy and new interfaces should use receiver matcher to explicitly say if the match should apply for zero only or any id. Maybe instead of "legacy API", which is opaque unless you know the history of this code, use something like createAllowingCatchAllDestination() > Source/WebKit/Platform/IPC/Connection.h:247 > + void removeWorkQueueMessageReceiver(ReceiverName, uint64_t destinationID = 0); Why don't we use std::optional<destinationID> here to match ReceiverMatcher behavior, making the comment unnecessary. > Source/WebKit/Platform/IPC/Connection.h:253 > + void removeThreadMessageReceiver(ReceiverName, uint64_t destinationID = 0); Ditto > Source/WebKit/Platform/IPC/MessageReceiveQueueMap.cpp:40 > + if (!matcher.destinationID) { I find !has_value() more readable when dealing with optionals with bool or sometimes-zero values. > Source/WebKit/Platform/IPC/MessageReceiveQueueMap.h:56 > + using AnyIDQueueMap = HashMap<uint8_t, StoreType>; Would be nice to add a comment to say that the key is a ReceiverName. > Source/WebKit/Platform/IPC/ReceiverMatcher.h:41 > + // Note: destinationID == 0 matches only 0 ids. Is a 0 ID valid? It would be clearer to be able to ASSERT(destinationID) here. > Source/WebKit/Platform/IPC/ReceiverMatcher.h:62 > + std::optional<ReceiverName> receiverName; > + std::optional<uint64_t> destinationID; This struct is going to end up as 128 bytes (or larger?) so maybe you should pass it around by reference.
Kimmo Kinnunen
Comment 10 2022-04-06 12:36:49 PDT
Created attachment 456848 [details] For landing
Kimmo Kinnunen
Comment 11 2022-04-06 12:47:46 PDT
(In reply to Simon Fraser (smfr) from comment #9) > Maybe instead of "legacy API", which is opaque unless you know the history > of this code, use something like createAllowingCatchAllDestination() Right, but that is then "legitimizing" the pattern. This commit is because we got into a bit of a pickle with overloading the value 0. The intention is to communicate that future uses won't end up calling that, rather using the struct here directly. I can of course rethink some other name. > > > Source/WebKit/Platform/IPC/Connection.h:247 > > + void removeWorkQueueMessageReceiver(ReceiverName, uint64_t destinationID = 0); > > Why don't we use std::optional<destinationID> here to match ReceiverMatcher > behavior, making the comment unnecessary. Because we're in a pickle of not knowing what ALL the callers mean with destinationID == 0. This would be a change of behavior. I don't want to do in this patch, I'd need to spend time going through all the many callers. I'll spend the time, but not in this patch. > > Source/WebKit/Platform/IPC/ReceiverMatcher.h:41 > > + // Note: destinationID == 0 matches only 0 ids. > > Is a 0 ID valid? It would be clearer to be able to ASSERT(destinationID) > here. Yes, 0 is valid and used. Hence much of the patch. I'll apply the changes tomorrow
Kimmo Kinnunen
Comment 12 2022-04-06 23:31:54 PDT
(In reply to Simon Fraser (smfr) from comment #9) > > Source/WebKit/Platform/IPC/ReceiverMatcher.h:62 > > + std::optional<ReceiverName> receiverName; > > + std::optional<uint64_t> destinationID; > > This struct is going to end up as 128 bytes (or larger?) so maybe you should > pass it around by reference. Interesting surprise to me I didn't spend any thought on. It's 24 bytes as a struct! https://godbolt.org/z/hKe4qq51v unoptionalized same feature would be 16 bytes!
Kimmo Kinnunen
Comment 13 2022-04-06 23:33:16 PDT
Created attachment 456894 [details] For landing
EWS
Comment 14 2022-04-07 06:36:12 PDT
Committed r292533 (249371@main): <https://commits.webkit.org/249371@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 456894 [details].
Radar WebKit Bug Importer
Comment 15 2022-04-07 06:37:15 PDT
Note You need to log in before you can comment on or make changes to this bug.