-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider optimizations for heavily-nested scenarios #75
Comments
Just to seed the discussion with a concrete idea, here's a simple optimization that might be sufficient to cover the generator+green-thread case: In the execution context, maintain a possibly-empty, 1-element "switch-cache" with two fields -- a tag
Obviously there are more complex scenarios (with multiple nested |
This would only be correct if the resumed continuation did not include a deeper switch handler for the same tag. We have the same problem when We should definitely have spec tests that exercise these edge cases.
This part shouldn't be necessary since switch handlers and suspend handlers with the same tag do not interfere with each other. (See #78) |
Oops, right; I was only thinking of the resuming a fresh continuation; thanks! (All the more reason to have these optimizations well-described and well-tested...) But yeah, saving this cache on the continuation itself makes sense as a fix.
Oh fantastic; I was hoping for exactly that and skimming the explainer for whether or not that was the case and thinking it might be a tweak to suggest to avoid the overhead of guarding for it all the time in this optimization. |
This introduces an IndexValue typedef, which is a union of Number and BigInt, and two algorithms, IndexValueToU64 and U64ToIndexValue, which can be used to convert between IndexValue and WebAssembly's u64 type (used in the embedding spec). It also makes several drive-by fixes and improvements.
Once this proposal gets to Phase 3 and we can study the performance of realistic workloads, I think it's important for this group to measure a workload that, e.g., uses stack-switching for both generators with green-threading where there are stacks of the form:
Because generator nesting depth is controlled by the user program, this N can be arbitrarily-large (e.g., generators can be called recursively) and a naive implementation will require an O(N) search when switching between green threads.
Assuming that the cost of this O(N) search isn't somehow amortized away, it seems like we should work out a predictable optimization that engines can perform so that, in practice, suspension to the green-thread-handler is O(1) (like a native engine would do). Although optimizing the O(N) case in general doesn't seem possible, identifying a subset of cases that cover the above scenario does seem imminently possible. However, I think it's important for us to have a proper shared discussion about what this predictable optimization is before declaring this feature finished so that (1) we can publish it in some form and continue to claim that wasm has predictable performance, (2) if there is some small tweak or addition to the proposal that would make the optimization significantly simpler or more effective, we still have the opportunity to make that tweak.
The text was updated successfully, but these errors were encountered: