Add bytecode VM for high-performance expression evaluation#35
Open
gryumov wants to merge 5 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #35 +/- ##
==========================================
+ Coverage 90.30% 97.03% +6.73%
==========================================
Files 4 8 +4
Lines 330 777 +447
==========================================
+ Hits 298 754 +456
+ Misses 32 23 -9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
📘 A preview of the documentation will be here soon |
c16a7a4 to
9d33b42
Compare
New evaluation path: compile_expr → eval_compiled (bytecode VM) alongside the existing parse_expr → eval_expr (tree walk). New files: - src/opcodes.jl: opcode constants with dispatch pattern - src/context.jl: VarContext shared variable registry - src/compiler.jl: CompiledExpr + post-order compiler (ExprNode → bytecode) - src/vm.jl: stack-based VM with zero-alloc evaluation - benchmark/benchmarks.jl: BenchmarkTools SUITE (PkgBenchmark-compatible) Key properties: - 400-900x faster than tree walk for typical expressions - Zero heap allocations with pre-allocated stack - 50-100 bytes per formula (vs ~1-3 KiB for ExprNode tree) - 63M+ evals/s throughput for bulk evaluation - Shared VarContext allows single values vector across all formulas New exports: VarContext, compile_expr, eval_compiled Version bump: 1.0.1 → 1.1.0 (new feature, non-breaking) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9d33b42 to
456962b
Compare
Add tg (tangent), ctg (cotangent), and mean (N-ary average) functions across all layers: eval, opcodes, compiler, and VM. The mean opcode uses an inline argument count byte to support variable arity. Refinements: eliminate heap allocations for tag-less variables (Nothing instead of empty Dict), add constant pool overflow check in compiler, broaden resolver to accept any callable (not just Function), and add optional sizehint to VarContext constructor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
These are pure math operations that belong in the VM level: - tg(x) -> tan(x), ctg(x) -> cos(x)/sin(x) - div(x,y), rem(x,y) for integer division and remainder - mean(x...) for variadic average Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
compile_expr→eval_compiled(bytecode VM) alongside existingparse_expr→eval_expr(tree walk)VarContextvariable registry for index-based lookup across all formulasbenchmark/benchmarks.jl)New files
src/opcodes.jlopcode()dispatchsrc/context.jlVarContextshared variable registrysrc/compiler.jlCompiledExpr+ post-order compilersrc/vm.jlbenchmark/benchmarks.jlNew exports
VarContext,compile_expr,eval_compiledVersion
1.0.1 → 1.1.0 (new feature, non-breaking)
Test plan
@allocatedjulia --project=benchmark -e 'using BenchmarkTools; include("benchmark/benchmarks.jl"); tune!(SUITE); run(SUITE, verbose=true)'🤖 Generated with Claude Code