perf: optimize JS tracer performance by reusing objects #305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a significant performance bottleneck in the JavaScript tracer implementation where new JS objects were created for every EVM instruction execution. The optimization introduces an object reuse pattern that dramatically reduces allocation overhead.
Changes
Core Implementation
step_object
anddb_object
fields toJsInspector
struct for reusable objectscreate_js_object_template()
methods for one-time object structure creationupdate_js_object()
methods for in-place data updates without recreationtry_step()
andtry_fault()
methods to use lazy initialization and object reusePerformance Optimization
Test Coverage
Backward Compatibility
All existing JavaScript tracer code continues to work unchanged. The original
into_js_object()
methods are preserved for compatibility.Test Results
All 46 tests pass, including 8 existing tests and 38 new tests specifically for this optimization.
Type of Change