Repository navigation
perf(vm,interp,jit): native call-site cache and single-pass dispatch across backends - #70
Merged
Merged
Conversation
…across backends Co-authored-by: esrrhs <esrrhs@163.com>
… PE and mark cold interp helpers noinline Co-authored-by: esrrhs <esrrhs@163.com>
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #70 +/- ##
==========================================
- Coverage 94.55% 94.50% -0.06%
==========================================
Files 130 130
Lines 32425 32482 +57
==========================================
+ Hits 30659 30696 +37
- Misses 1766 1786 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Dec 2, 2026
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
Eliminates redundant argument packing, hash lookups, and boundary overhead on native function call hot paths across all three backends (
JIT_INTERP,JIT_TCC,JIT_GCC):CallByNameImpl(src/jit/vm.cpp)CallNativeEntryand routed!jit_funcdirectly before JITVarMultipacking, eliminating double argument flattening and wastedVarMulti::AllocTemparena allocations on variadic native calls while preserving strict arity checks for fixed-arity natives.FlCallCachepopulation inFakeluaCallByNameCachedfor bothJIT_GCCandJIT_TCC(resettingcache->version = 0on miss), and routed already-cachedkind == 2fallbacks (e.g.VAR_MULTIexpansion likeselect(i, ...)) directly toCallNativeEntrywithout redundant hash lookups.src/compile/c_runtime_cov.h)FlCallNamed0..12to serve bothFAKELUA_JIT_TYPE == 1(GCC) andFAKELUA_JIT_TYPE == 0(TCC), and allowedcache->kind == 2variadic native functions (cache->is_vararg || cache->expected_args == N) with noVAR_MULTIarguments to hitFakeluaCallNativeCacheddirectly.MAKEMULTI/COMBINE(src/interp/func_proto.h,src/interp/interpreter.cpp)const NativeFuncEntry *nativetoInterpCallCache(sharingvm_versioninvalidation) and dispatched cached native calls directly in bothCALLNAMEandTAILNAME(InterpCallNativeDirect/InterpCallNativeSlow), preservingCurrentJit(), exact Lua source locations, and call stacks on exceptions.std::vector<CVar>heap allocations inMAKEMULTI/COMBINEwith directstk + basepass-through (!HasBoxes) and a stack small-buffer fast path up tokMaxFunctionInputParams(HasBoxes).state->CurrentJit()intable.sort&xpcall(src/native/table/native_table.cpp,src/native/basic/native_basic.cpp,src/state/fakelua.cpp)JIT_TCCwithstate->CurrentJit()intable.sort's custom comparator andxpcall's error handler, while tighteningDispatchCall((!cl || IsGccClosure(cl))) so cross-backend TCC closures invoked from GCC remain guarded byRunWithJitErrorBoundary.test/test_native.cpp)VAR_MULTIexpansion +MAKEMULTI/COMBINEwith boxed locals, cached native error locations & call stacks (CALLNAME&TAILNAME),vm_versioncache invalidation on native/Lua redefinition, andtable.sort/xpcallacross all 3 backends plus cross-backend TCC-in-GCC closures.Verification
GCC 13.3.0 -O3 -DNDEBUG): 0 warnings insrc/andtest/test_native.cpp.flua cmd/test.lua: passed across--jit_type=0(TCC),--jit_type=1(GCC), and--jit_type=2(INTERP).unit_tests(withFAKELUA_HOMEset): 1839 / 1862 passed (48 suites, includingcommon.c_runtime_cov_matches_kCRuntimeHeaderand all 4 new tests); the 23 failures are exclusively environmental MySQL (17) / Redis (6) integration tests with no local daemons on the VM.Benchmarks (Master
358697f8vs Branch)Measured on Linux 6.12 (Intel Xeon,
taskset -c 0 ./bench_mark --benchmark_min_time=0.2s --benchmark_repetitions=1, Release-O3 -DNDEBUG, PUC-Rio Lua 5.4.8):