-
-
Notifications
You must be signed in to change notification settings - Fork 569
Improve interop performance against dictionary #2088
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
Conversation
0541d32
to
395384b
Compare
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.
Pull Request Overview
This pull request improves interop performance when working with dictionaries and native JsValue conversions and updates the caching mechanisms involved in array-like wrappers, delegate conversion, and operator overload method lookups. The changes include refactoring the array-like wrapper resolution for performance, updating delegate caching in type conversion, modifying function construction and object conversion, and adding caching for extension and operator overload methods.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
File | Description |
---|---|
Jint/Runtime/Interop/ObjectWrapper.cs | Refactored array-like wrapper resolution using a ConcurrentDictionary and optimized property access. |
Jint/Runtime/Interop/DefaultTypeConverter.cs | Updated delegate caching mechanism with ConditionalWeakTable and improved array conversion check. |
Jint/Native/Function/Function.cs | Simplified constructor parameters and added a ToObject override to return the delegate directly. |
Jint/Extensions/ReflectionExtensions.cs | Introduced caching for operator overload method lookups to reduce reflection overhead. |
Comments suppressed due to low confidence (1)
Jint/Runtime/Interop/DefaultTypeConverter.cs:135
- [nitpick] The variable name 'astFunction' could be more descriptive (e.g., 'functionDefinition') to clarify that it represents the underlying function definition for delegate caching.
var astFunction = (func.Target as Function)?._functionDefinition?.Function;
395384b
to
9f46d98
Compare
I want to see the issue updated with the new results now. |
I copied the benchmarks and modified to support running as single (params for scenario) with addition of projecting to JsValue data (ideal). So I would guess this reflects the original problem. |
The codebase is mostly benchmarked against JS scenarios so these interop ones can be tricky. You could probably start a consulting business about the performance traps with interop and JS... |
Here's the full non-compared benchmark result:
|
I'm adding the test case and also the option which shows converting to native
JsValue
objects from JSON deserialization. If use case is reading then native types should produce best performance. I might have made mistakes so take it with a grain of salt.The delegate building is now cached against AST node reference so it should align quite well with the idea of preparing and caching AST when needed.
Jint.Benchmark.InteropLambdaBenchmark
fixes #2087