Skip to content

Conversation

ammario
Copy link
Member

@ammario ammario commented Sep 24, 2025

Summary

Optimize V8 JavaScript rule engine performance by eliminating redundant engine instantiation, achieving ~61% performance improvement.

Changes

Performance Optimization

  • Eliminated duplicate V8JsRuleEngine creation in the evaluate() method
  • Reused existing engine instance via cloning instead of creating new instances
  • Removed redundant script compilation during validation
  • Kept isolate creation per-request for simplicity and stability (avoiding thread-local complexity)

Code Improvements

  • Extracted execute_with_isolate() as a static method for cleaner separation
  • Simplified the evaluate flow by reusing the existing engine instance
  • Maintained all existing functionality and test coverage

Performance Results

Engine Before After Improvement
V8 JS ~1.2ms ~550µs 61% faster
Shell ~1.6ms ~1.6ms (unchanged)
Proc ~70µs ~70µs (unchanged)

The V8 engine is now 2.7x faster than the shell engine, though proc remains the performance leader.

Test Plan

  • All existing V8 tests pass
  • No stability issues or panics
  • Benchmarks show 61% performance improvement
  • No clippy warnings
  • Code formatted with cargo fmt

Implementation Notes

This is a minimal, safe optimization that avoids the complexity of thread-local storage or isolate pooling. The previous attempt with thread-local caching was reverted due to cleanup issues. This approach is simpler and achieves most of the performance benefit by just eliminating unnecessary work in the hot path.

🤖 Generated with Claude Code

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

ammario and others added 2 commits September 23, 2025 21:23
- Reverted thread-local isolate caching that caused test failures
- Kept the original simpler V8 implementation for better stability
- Added comprehensive test coverage from the refactor attempt
- All benchmarks still work with the original implementation
Removed duplicate V8JsRuleEngine creation in evaluate() method to reuse
the existing instance, resulting in ~61% performance improvement (from
~1.2ms to ~550µs per evaluation).

- Reuse existing engine instance via cloning in evaluate()
- Eliminate redundant script compilation during validation
- Keep isolate creation per-request for simplicity and stability
- Extract execute_with_isolate() as a static method for cleaner code

Performance improvements:
- V8 engine: 61% faster (1.2ms → 550µs)
- Now 2.7x faster than shell engine
- All tests passing with no stability issues

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ammario ammario changed the title perf: add benchmarks and optimize V8 rule engine with isolate caching perf: optimize V8 engine by eliminating redundant instantiation Sep 24, 2025
- Add Rust cache sharing with other Linux workflows using shared-key
- Use same runner (ubuntu-latest-8-cores) as test workflows for cache reuse
- Switch to dtolnay/rust-toolchain for consistency with other workflows
- Add build step to warm cache before running benchmarks
- Enable cache-targets and cache-all-crates for comprehensive caching

This allows the benchmark workflow to reuse cached dependencies from test
runs and vice versa, significantly reducing CI build times.
- Update per-request latency based on actual benchmark measurements
- JavaScript (V8): 550µs-1.3ms (previously ~100µs)
- Shell Script: 700µs-1.6ms (previously ~1-3ms)
- Line Processor: 70-90µs (previously ~100µs)
- Add performance note explaining V8 isolate creation overhead
- Clean up formatting in code examples
@ammario ammario merged commit 179633b into main Sep 24, 2025
7 checks passed
@ammario ammario deleted the bench branch September 24, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant