-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
src,test: ensure that V8 fast APIs are called #54317
Conversation
Review requested:
|
Context: I have a working implementation for V8 12.8 in targos@b6a84ac. Unfortunately, the V8 version in |
You don’t have to put this in the Environment or make it associated with an isolate at all - using a thread_local map should already be enough. |
Thanks @joyeecheung. I changed it to use a |
My only concern is that while working on anything related to performance, I always build node.js in release mode (not in debug). hence, the need to build performance pull-requests in different release modes, might increase the barrier and friction to contribute. Is there a possibility of enabling these checks by default but somehow the official release builds doesn't contain the output of this macro? or, can we introduce a new build flag to enable this on release builds without having to additionally build debug? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #54317 +/- ##
==========================================
- Coverage 87.09% 87.09% -0.01%
==========================================
Files 647 647
Lines 181816 181843 +27
Branches 34884 34890 +6
==========================================
+ Hits 158360 158376 +16
- Misses 16764 16771 +7
- Partials 6692 6696 +4
|
Adds a debug-only macro that can be used to track when a V8 fast API is called. A map of counters is maintained in in thread-local storage and an internal API can be called to get the total count associated with a call id. Specific tests are added and `crypto.timingSafeEqual` as well as internal documentation are updated to show how to use the macro and test fast API calls without running long loops.
9a9d4e7
to
b042120
Compare
@anonrig I tried to address all your review comments.
Since the macros are used in performance-sensitive paths, I wanted them to have 0 impact in release mode, so that's why I chose to use debug mode as the condition. |
This comment was marked as outdated.
This comment was marked as outdated.
thread_local std::unordered_map<std::string_view, int> v8_fast_api_call_counts; | ||
|
||
void TrackV8FastApiCall(std::string_view key) { | ||
v8_fast_api_call_counts[key]++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the purpose of the tests, I think using a bool should be enough - an int would overflow if the process runs for long enough.
Also if we require the counter/toggle to be pre-declared in a macro list, we can just track them in thread_local bool instead of doing a runtime map lookup, and the overhead of simply setting a variable to true feels negligible enough to be enabled at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an int would overflow if the process runs for long enough
I know that but I don't think it matters. As an internal debug-only API, it is not meant to be useful outside of our unit tests and those would never run for long enough.
I thought a counter could be useful for complex cases where we want to call the same API multiple times (or it's called in a loop internally).
I'd say feel free to refactor / change in a future PR (or block this one). I spent enough energy on it myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought a counter could be useful for complex cases where we want to call the same API multiple times (or it's called in a loop internally).
Even if it's called multiple times, only V8 can really reliably check exactly how many times the fast API is run, as that's subject to the optimizing strategy - unless we use the intrinsics that are not supported for embedders' use cases. As an embedder a true/false is the best we can count on.
I'd say feel free to refactor / change in a future PR (or block this one). I spent enough energy on it myself.
Sorry if this is untimely - feel free to land it, just trying to address the previous comments about release/debug differences.
Landed in 1d35a06 |
Adds a debug-only macro that can be used to track when a V8 fast API is called. A map of counters is maintained in in thread-local storage and an internal API can be called to get the total count associated with a call id. Specific tests are added and `crypto.timingSafeEqual` as well as internal documentation are updated to show how to use the macro and test fast API calls without running long loops. PR-URL: #54317 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Adds a debug-only macro that can be used to track when a V8 fast API is called. A map of counters is maintained in in thread-local storage and an internal API can be called to get the total count associated with a call id. Specific tests are added and `crypto.timingSafeEqual` as well as internal documentation are updated to show how to use the macro and test fast API calls without running long loops. PR-URL: #54317 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Adds a debug-only macro that can be used to track when a V8 fast API is
called. A map of counters is maintained in the Node.js environment and
an internal API can be called to get the total count associated with
a call id.
Specific tests are added and
crypto.timingSafeEqual
is updated toshow how to use the macro and test fast API calls without running long
loops.