-
-
Notifications
You must be signed in to change notification settings - Fork 41
⚡ perf: Add @branchHint optimizations to EVM execution paths #1799
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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
Caution Review failedThe pull request is closed. WalkthroughThis set of changes focuses on documentation enhancements, code style clarifications, and performance optimizations for a Zig-based Ethereum Virtual 8000 Machine (EVM) implementation. Key updates include new and expanded documentation, the addition of branch prediction hints for hot and cold paths, API alias reorganization, and improvements to unsafe stack operations for better performance and clarity. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ZigCompiler
participant EVM
participant Stack
participant JumpTable
participant Frame
User->>EVM: Run EVM execution (interpret_with_context)
EVM->>ZigCompiler: @branchHint(.likely) for main loop and opcode fetch
EVM->>JumpTable: Execute opcode (with branch hints)
JumpTable->>Stack: Perform stack operations (with branch hints)
JumpTable->>Frame: Consume gas (with branch hints)
Stack->>Stack: Unsafe operations with branch prediction
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
…ug logging Implement cross-platform logging system using std_options.logFn that works consistently across all target architectures including native platforms, WASI, and WASM environments. Add comprehensive debug logging throughout core EVM components for better development experience and debugging. ## Implementation Strategy ### Step 1: Create std_options configuration - Created src/std_options.zig with custom logFn for multi-platform support - Compile-time target detection for zero runtime overhead - Platform-specific backends: native (stderr), WASI (stderr), WASM (buffer + JS interop) - Dead code elimination removes unused backends ### Step 2: Platform-specific logging backends - Native platforms: Use std.log.defaultLog for stderr/stdout - WASI: stderr writer with proper error handling - WASM (freestanding): Dual approach with buffer + optional JS console interop - Export functions for JS integration: getLogBuffer(), getLogBufferLen(), clearLogBuffer() - Thread-safe buffer management with mutex protection ### Step 3: Update existing logging module - Modified src/evm/log.zig to use std.log for isomorphic behavior - Removed inline keywords for consistent bundle size optimization - Added info() function for general information logging - Maintained EVM-specific log prefixing for easy identification ### Step 4: Add comprehensive debug logging - VM execution: initialization, interpretation context, depth tracking - Jump table: opcode execution, gas consumption, validation errors - State management: storage operations, initialization tracking - Stack operations: push/pop operations, overflow/underflow detection - Memory management: resize operations, byte access, limit enforcement ## Technical Specifications ### File Structure - src/std_options.zig (new): Isomorphic logging configuration - src/evm/log.zig (modified): Updated API using std.log - src/evm/vm.zig (modified): Added VM execution logging - src/evm/jump_table.zig (modified): Added opcode dispatch logging - src/evm/evm_state.zig (modified): Added state operation logging - src/evm/stack.zig (modified): Added stack operation logging - src/evm/memory.zig (modified): Added memory operation logging ### Target Platform Support - linux, macos, windows, freebsd: Native stderr/stdout logging - wasi: WASM with system interface support - freestanding + wasm32/wasm64: Browser/Node.js WASM environments - Other platforms: Fallback to default or no-op logging ### Performance Considerations - Compile-time target detection (zero runtime overhead) - Debug logs optimized away in release builds - Efficient buffer management for WASM (8KB buffer with wraparound) - Mutex protection for thread-safe buffer access - Minimal memory footprint for embedded targets ### Error Handling - All logging errors are non-fatal - Graceful fallback when JS interop unavailable - Buffer overflow protection with safe wraparound - Memory allocation failure handling - Silent operation in resource-constrained environments ## Success Criteria Achieved ### Functional ✅ Logging works identically across all target platforms ✅ WASM builds compile and run without logging errors ✅ Existing codebase requires no changes to logging calls ✅ JavaScript can read logs from WASM modules via exported functions ✅ Comprehensive debug logging added to core EVM components ### Quality ✅ Code follows project style guidelines (snake_case, 120 char width) ✅ Implementation is maintainable and well-documented ✅ Performance overhead is minimal (compile-time optimization) ✅ Error handling is robust and non-intrusive ✅ All tests pass (zig build test-all) ### Integration ✅ Seamless replacement of existing logging system ✅ No disruption to development workflow ✅ Clear path for future logging enhancements ✅ Compatible with existing build system and CI ✅ Maintains API compatibility while improving functionality The isomorphic logging system enables consistent debugging across all deployment targets while the comprehensive debug logging provides detailed insights into EVM execution flow, making development and troubleshooting significantly more effective. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Added @branchHint(.likely) to hot execution paths in VM, jump table, and stack operations - Added @branchHint(.cold) to error handling paths in jump table validation - Fixed missing semicolon in stack.zig peek_unsafe function - Added camelCase method aliases for stack operations to maintain API compatibility - Optimized branch prediction for common EVM operations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…ntation - Add emoji conventional commit requirement for all commits and PRs - Add instruction to include original prompts in <prompt></prompt> XML tags - Add Zig-specific testing requirements (zig build test-all mandatory) - Update style rules: no inline keyword, prefer if (\!condition) unreachable - Add performance guidelines with @branchHint usage - Create comprehensive src/evm/CLAUDE.md documenting EVM implementation - Document two-stage safety system and performance optimization techniques - Include opcode organization, testing patterns, and contribution guidelines <prompt> Add to the CLAUDE.md the instruction that whenever possible the original prompt should be included in the pr description nested in <prompt></prompt> xml tags. Also add a CLAUDE.md file to src/evm/CLAUDE.md (you will have to create the file). Explore the evm implementation and write a useful CLAUDE.md. Include the instructions that we should not use the inline keyword so the compiler has best ability to make wasm bundle size small or performance fast at it's wish. Also in the root CLAUDE.md mention we prefer if (\!foo) unreachable over std.debug.assert as the first is more readable and the literal implementation of the 2nd. Add to the main claude.md that no zig code should ever be committed until zig build test-all is run. Add that we should run zig build test-all early and often because the zig tests run so fast so the feedback is useful and worth it. After doing all this make a commit following the commit instructions you just wrote but use gt branch create -m "<MESSAGE>" this time rather than git </prompt> 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Description
Added
@branchHint
annotations to optimize performance in critical EVM execution paths. These hints help the compiler generate more efficient code by indicating which branches are more likely to be taken during execution.Also cleaned up the Stack implementation by:
Updated tests to use snake_case method names where appropriate.
Testing
All existing tests continue to pass with the updated method names. The changes are performance-oriented and don't affect functionality.
Additional Information
Your ENS/address:
Summary by CodeRabbit
Documentation
Style
Refactor
Tests