-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Start to add rust backed request execution under a feature-flag by rewriting ConfigRequest #9658
Start to add rust backed request execution under a feature-flag by rewriting ConfigRequest #9658
Conversation
I actually want to remove ConfigRequest completely. It's not a real request at the moment actually since it doesn't do any work. The configs have actually already been loaded, and the ConfigRequest is fake just to setup the request graph structure. In reality, it isn't necessary at all - the invalidations could just be added to the parent request. The config loading doesn't get invalidated separately right now anyway. In addition, it looks like there's a lot of bridging here. Since ConfigRequest doesn't actually do any work other than mutating the graph, now we're calling into rust only to call back into JS several times. Maybe ConfigRequest was just an example of the setup but perhaps it would be more efficient to do the request work in rust and send back all the invalidations at once as part of the result rather than calling back to JS via the RequestApi a whole bunch of times? |
That makes sense; the purpose of this PR is:
Yes this is just an example so it doesn't do anything interesting. That said, I feel strongly we should not optimise anything without measuring. The benchmarks added in https://github.com/yamadapc/napi-benchmark/tree/main show there's very low overhead to call JavaScript functions from rust (nanosecond cost for calls in of themselves). Optimising without benchmarks or measurements has a high risk of implementing something that is at the same time hard to understand and that potentially isn't faster than a naive implementation. |
Essentially, for every 1 JavaScript execution context/worker, napi demands 1 dedicated Rust thread. You cannot pass JavaScript references between threads (with some exceptions) so data is typically handled through channels. If you want to do non blocking JS behaviours, that must be factored into the way you write the napi bindings and is quite verbose. |
Merge queue setting changed
Does not achieve anything in particular other than set patterns for exposing/integrating rust code under a flag.
While implementing unit-tests for the
ConfigRequest
I found a bug whereinvalidateOnEnvChange
would not be picked-up on its own.There are exhaustive tests for the config request current/previous implementations added.
For the hashing section, there is a slight missing part regarding sorting of object keys.