Repository navigation
perf(interp): inline GETTABLE/SETTABLE hot paths for arr_ and quick_data_ - #74
Merged
Merged
Conversation
…data_ Co-authored-by: esrrhs <esrrhs@163.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #74 +/- ##
==========================================
+ Coverage 94.52% 94.54% +0.01%
==========================================
Files 130 130
Lines 32588 32669 +81
==========================================
+ Hits 30803 30886 +83
+ Misses 1785 1783 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Inlines the hot paths of
VM_CASE(GETTABLE)andVM_CASE(SETTABLE)directly in the interpreter dispatch loop (src/interp/interpreter.cpp), with out-of-linenoinlineslow paths for misses, resizes,nildeletions, const/spec tables, float normalization, and errors. Bytecode encoding and instruction set are unchanged.Changes
src/var/var_string.h: AddedVarString::CachedHash()so the hot loop reads the precomputedConstStringdjb2 hash (ConstString::Allocalways populates it) without pullingVarString::HashOfintoInterpreterExecuteT.src/interp/interpreter.cpp:[[noreturn]] __attribute__((noinline, cold)) InterpThrowIndexErrorand zero-frame__attribute__((noinline))InterpGetTableSlow/InterpSetTableSlowhelpers that tail-callTableHelper::GetTableInt/GetTable/SetTable(avoiding stack-canary overhead and the double cross-TU hop throughinterp_rt::SetTable).VM_CASE(GETTABLE):arr_lookup ((uint64_t)k - 1 < tbl->arr_size_) for plain and const tables (spec tables never allocatearr_).quick_data_short linear probe whenspec_get == nullptr && spec_count == 0 && bucket_count_ == 0forkIntkeys andkStringIdkeys (hash-checked first; non-pointer-equal hash matches fall back toInterpGetTableSlowto handle dynamicVarStringkeys, cross-StateStringIds, and djb2 collisions).VM_CASE(SETTABLE)(non-const tables):arr_overwrite (seq_len_unchanged).arr_append whenidx == arr_size_ && arr_size_ < arr_cap_ && count_ == 0 && v != nil, updatingseq_len_in O(1).quick_data_kStringIdnon-nil update-in-place and append (count_ < QUICK_DATA_SIZE) whenspec_set == nullptr && spec_count == 0 && bucket_count_ == 0.InterpreterExecuteT<false>grows from0x4184to0x46f9(+1,397 B, +8.3%) with zero regression on unrelated loops (Fibonacci,Sum).test/test_table.cpp:interp_table_fastpath_edge_cases_across_backendscovering const table reads,arr_growth &#twith/without holes, nil deletion/refill, float-exact-int (1.0/2.0/-0.0) &1.5keys, negative/zero/OOB/mininteger/maxintegerint keys,quick_data_hits/misses/djb2 collisions ("ab"vs"bA")/dynamic-string aliasing/rehash, self-aliasingGETTABLE, boxed locals (InterpreterExecuteT<true>), ABIspec_counttables, andNativeObjectspec tables (spec_get/spec_set).interp_table_error_location_and_stack_across_backendsverifying error messages, Lua source lines, and multi-frame call stacks for non-table,nil-key,NaN-key, and const-table errors across all 3 backends (INTERP,TCC,GCC).Benchmarks (
origin/master @ b686d2e4vs this branch)GCC 13.3.0 Release (
-O3 -DNDEBUG), Linux x86_64, core-pinned (taskset -c 0), 3-rep median (--benchmark_min_time=0.2s --benchmark_repetitions=3), compared against PUC-Rio Lua 5.4.8:(Note:
BinarySearchis dominated by twoGETGLOBALhash lookups ofsearch_init_valsper inner-loop iteration;HashInsert/TableInsert/HashLookupdeltas are within the 2–3% Lua baseline drift observed during the run.)Verification
-O3 -DNDEBUG): 0 warnings insrc/andtest/test_table.cpp.flua cmd/test.lua: PASS (exit 0) across all 3 backends (--jit_type=0TCC,--jit_type=1GCC,--jit_type=2INTERP).unit_tests(FAKELUA_HOME=/agent/repos/fakelua): 1860 / 1883 passed (includingcommon.c_runtime_cov_matches_kCRuntimeHeaderand all 41test_table.*tests; only the 23 environmental integration tests requiring local MySQL/Redis daemons fail locally).