Sculk perf - #227
Closed
casperwtf wants to merge 7 commits into
Closed
Sculk perf#227casperwtf wants to merge 7 commits into
casperwtf wants to merge 7 commits into
Conversation
added 7 commits
October 4, 2026 22:50
Every direct call ran Shaded.checkInterruption, a static call that reads the current thread's interrupt flag. Backward branches, call_indirect dispatch and calls to imported functions keep their checks, and a direct call keeps its check when the callee sits on a cycle of the direct call graph (found with Tarjan's algorithm), so recursion such as power.c, which runs 2^n calls at depth n, still stops when the thread is interrupted. Calls into acyclic helpers, most of a compiled AssemblyScript or Rust module, no longer pay for the check.
Instance.global(int) asked ImportValues for its global count twice and then indexed either the import list or the module's own globals. Compiled code calls it through Shaded.readGlobal and Shaded.writeGlobal on every global.get and global.set, and AssemblyScript and Rust modules touch their stack and heap pointers in most functions. Keep one array covering the whole global index space, imports first, filled as globals are created.
…dules ByteArrayMemory keeps memory in 64 KiB pages so a shared memory can grow while other threads read it. Every load and store pays for that: it loads the page from the page table, masks the offset, and checks whether the access straddles two pages before the VarHandle access and its own bounds check. A memory that is not shared has no concurrent readers, so it can live in one byte array and grow by copying, leaving one bounds-checked access per load or store. FlatByteArrayMemory rejects shared limits and caps growth at RUNTIME_MAX_PAGES, the largest size one Java array can hold. With it as the default for every unshared memory, the runtime, compiler, spec and WASI suites pass (96,560 tests). It is opt-in through Instance.Builder withMemoryFactory(FlatByteArrayMemory::new).
A WasmModule keeps every function's parsed instructions for as long as the module lives, and an Instance and its compiled MachineFactory keep the module. Compiled machines never read those instructions; only the interpreter does. For a host running many large modules this is the largest single cost on the heap: 72 AssemblyScript modules kept 8.5 million AnnotatedInstruction objects and their operand arrays, about 740 MiB. MachineFactoryCompiler.Builder#withReleasedFunctionBodies hands instances a copy of the module (WasmModule#withCodeSection) whose compiled functions keep only their local types. Functions left to the interpreter keep their instructions. Modules loaded from a cache keep theirs, since the cache does not record which functions were interpreted.
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.
No description provided.