perf: optimize JS tracer performance by reusing objects#305
Draft
perf: optimize JS tracer performance by reusing objects#305
Conversation
This change eliminates the performance bottleneck in JavaScript tracing where new objects were created for every EVM instruction execution. Key improvements: - Added object reuse pattern with lazy initialization for step and database objects - Implemented create_js_object_template() and update_js_object() methods - Modified try_step() and try_fault() to reuse objects instead of recreating - Reduced object allocation from millions per trace to 2 per tracer instance - Added comprehensive test suite with 38 new tests covering unit, integration, and performance scenarios Performance impact: - Before: 2 new JS objects created per EVM instruction (potentially millions per transaction) - After: 2 JS objects created once per tracer instance, then updated in-place - Expected: Significant reduction in allocation overhead and garbage collection pressure Backward compatibility maintained - existing JavaScript tracer code works unchanged.
- Add enter_frame_object and exit_frame_object fields to JsInspector - Implement create_js_object_template and update_js_object for CallFrame and FrameResult - Update try_enter and try_exit to use lazy initialization and object reuse - Add comprehensive tests for enter/exit optimization - This completes the object reuse pattern for all JS tracer hot paths
- Replace assert_eq with assert for boolean comparisons - Use inline format args - Add #[allow(dead_code)] to unused into_js_object methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_objectanddb_objectfields toJsInspectorstruct 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