Repository navigation
feat(jit): filesystem shared-library cache with isolated state binding - #56
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #56 +/- ##
==========================================
- Coverage 89.96% 88.79% -1.18%
==========================================
Files 125 127 +2
Lines 28838 29649 +811
==========================================
+ Hits 25945 26326 +381
- Misses 2893 3323 +430 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
libc++ on macOS uses __int128 for file_clock ticks, which has no operator<< and broke the BuildWithMacOS compile.
MinGW last_write_time often comes from stat() and is only 1-second resolution, so a same-size header rewrite in the same process could reuse a stale FileDigest and miss invalidation.
Open cache images, manifests, and lock files with FILE_SHARE_DELETE, and unlink with POSIX disposition so an external cleaner can remove a tree without waiting on Restore or a held lock handle. MinGW libstdc++ remove_all can livelock in __erase when a child is open or delete-pending and fs::remove fails without an error_code; the Windows Test job hit that in gcc_cache_external_cleanup_races_restore_without_partial_copy and timed out after 60 minutes. Cache eviction now uses a one-pass Windows walker, StillLinked compares file identity after an unlink, and the cleanup-race tests use the same non-retrying delete.
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
Implement a best-effort filesystem cache for GCC/Clang JIT shared libraries while keeping runtime data isolated per loaded image.
__fakelua_bind. Literal bytes and numeric constants remain in generated C; canonical strings and runtime objects remain State-owned.StateGCCConfig.enable_cache(default true) /cache_directory, documentation in both READMEs, and a reproducible public-API benchmark harness. TCC stays in-memory; INTERP is not cached. No new dependency is introduced (OpenSSL is already linked).Additional review regressions and discovered fix
Added six further cases beyond the original cache tests, in their existing jitter/exception modules:
Case 3 reproduced a real crash (exit 139) before the fix. The binder now returns the exact image's Lua-location pointer and the GCC/TCC handle owns it before init runs, including throwing/reentrant init paths. Do not infer ownership from
GetLuaLocs().back()after successful init.Existing new cache cases also cover 8-thread/4-process races, abrupt process exit with held lock/partial staging, independent States, native callbacks, all 256 byte values/NUL/binary keys, hash collisions, diagnostics filenames, compiler/header/source/debug invalidation, cache disable/fallback and compile failure not publishing.
Local validation
addr2lineonly to avoid prohibitively slow C++ stacktrace symbolization; this was not used for the separate 16-test run. Network/process/database integration suites are not claimed as locally run.git diff --checkpasses. Original unrelated coverage/log artifacts and all build outputs are excluded from this PR.Reproduce the scoped groups from the Release build's
bindirectory:Performance (initial cache implementation, before the FIFO/formatting follow-up)
Linux x86_64, GCC 14.2.0, Release
-O3, CPU 7 pinned, 9 samples per invocation, same public-API harness and Lua workload; no concurrent builds/tests from this task. Baseline library/header are the unmodifiedcc0e0c84873b4d4de2d75acc181e3bd0104e1e12, built before edits. Same-process warm median excludes the first cold sample.The persistent image checksum and mtime remained unchanged across independent execs, with exactly one image in a confirmed fresh benchmark cache.
These are representative microbenchmarks, not a universal zero-regression guarantee. Embedded address immediates become static-variable reads; filesystem lookup/intern callbacks do not enter the JIT operation hot path. Lua frontend work and a cheap compiler-version metadata query remain on a cache hit. The once-per-load binder also returns the diagnostic location; it is not a runtime dispatch table.
The standalone benchmark README was removed at the user's request. The harness remains in
tools/benchmark_jit_cache.cpp. Build against the matching current header/library, e.g.:c++ -O3 -std=c++23 -Iinclude tools/benchmark_jit_cache.cpp -Lbuild/lib -lfakelua \ -Wl,-rpath,"$PWD/build/lib" -o /tmp/benchmark-jit-cacheThen run:
taskset -c 7 ./benchmark-jit-cache cold /tmp/fakelua-cache-benchmark-cold taskset -c 7 ./benchmark-jit-cache warm /tmp/fakelua-cache-benchmark-warm taskset -c 7 ./benchmark-jit-cache warm /tmp/fakelua-cache-benchmark-warm # new processFor the unmodified base, build this same harness with
-DFAKELUA_CACHE_BASELINE, its original header and baseline library. This excludes only the new cache configuration API, not any measured loop/code.Limits / operational notes
Use a trusted private local cache directory. The default is now the original temp tree:
<system-temp>/fakelua/cache/uid-<uid>on POSIX or<system-temp>/fakelua/cacheon Windows,selected by the same helper as transient JIT workspaces.
cache_directorystill overrides it.cache_max_entriesdefaults to 256 complete entries; 0 means unlimited, not disabled.Eviction is FIFO by publication sequence, not access time, and runs on lookup/publication.
A directory-wide thread/process lock coordinates restore/publication/eviction; C compilation
remains outside it. 256 fixed key-lock stripes plus one index lock bound lock metadata;
eviction never unlinks lock files. Stripe collisions can serialize unrelated compiles.
Deletion/permission failures are best effort and may leave temporary overshoot; clients
sharing a directory should use the same count limit. This is not a byte-size limit.
System temp cleanup is policy-dependent, not guaranteed. Deletion of cache entries/the
cache subtree is expendable acceleration: misses recompile and loaded private modules
survive. POSIX external unlink can detach active lock inodes, so file locking alone is
not claimed to solve that case: detached locks are checked, staging paths are writer-private,
publication is atomic and executable bytes are verified before private-copy loading.
Concurrent external cleanup can cause redundant compilation/cap overshoot, not partial-image
execution. Interrupted writers may leave uncounted
.tmp.*directories; clean while idle.For deterministic manual cleanup, stop cache users first, especially before deleting locks. A State's existing single-threaded-use contract is unchanged: concurrency tests use independent States. Custom/hidden-input toolchains must opt out, and toolchains should not be mutated during compilation.
Requested follow-up: temporary defaults, FIFO and generator organization
GetTmpDirectory()for the original system-temp/fakelua tree; POSIX private UID leafstays 0700, symlinks/insecure or foreign-owned parents are rejected. No home/XDG/LOCALAPPDATA default.
recovery), count complete image/manifest pairs only, and preserve unrelated/partial files.
from inside the directory lock. Loaded private copies continue running after eviction.
CGen::GenerateBindings()and use Includes/StringDecls/Bindings Sections; removespecial prefix/local-stream concatenation. The binder ABI and once-per-load hot-path design are unchanged.
POSIX permissions/symlinks, FIFO/0/lowered limits/non-LRU hits/corrupt ages, threaded/process publishers,
bounded lock metadata, preservation of unrelated files/loaded images, root/entry deletion,
unlink of a held process lock, and cleanup racing restore/compilation/live execution.
without sandbox or symbolizer replacement.
root
.clang-format, using clang-format 21.1.8; 71 files changed, in a separateformatting-only commit. Excluded checked-in generated Flex/Bison outputs and vendored
src/platform/FlexLexer.h, plus all untracked/build/dependency trees and unsupported languages.--dry-run --Werror). Lua/other raw stringliterals were checked unchanged. The formatted C runtime coverage view was synchronized
byte-for-byte into
kCRuntimeHeader; preprocessed runtime tokens match the pre-format version.without sandbox or a symbolizer replacement (145.470 seconds). This is the final follow-up's
actual scope, not a claim to rerun all 1208 older scoped cases or external integration suites.
env -u CPM_SOURCE_CACHE cmake --build build-cpm-fix --target unit_tests -j 2build-cpm-fix/bin:./unit_tests --gtest_filter='jitter.*:state.*:runtime.*:vm_cvar_call.*:common.*:syntax_tree.*:util.*:var.*:native.gcc_cache_*:exception.gcc_cache_*'Final follow-up release measurements
Same public-API harness, Linux x86_64,
/usr/bin/g++14.2.0, Release library,CPU 7 pinned, nine samples per invocation, no concurrent build/test from this task:
Cold-to-warm compilation is about 349x for this workload. Final same-process warm
steady-state medians (arithmetic / dynamic field / string comparison / varying
interned lookup) are 25.808 / 48.63425 / 20.7931 / 66.049 ms. The unmodified-base
results above were measured earlier, not a newly interleaved baseline run; do not
interpret noise or these examples as a universal zero-overhead guarantee.
Reproduce this follow-up with the existing local Release layout: