You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugIssue identified by VS Code Team member as probable bugchat-terminalThe run in terminal tool in chatfreeze-slow-crash-leakVS Code crashing, performance, freeze and memory leak issuesimportantIssue identified as high-priorityinsiders-releasedPatch has been released in VS Code InsidersverifiedVerification succeeded
#273177 caused us to disable auto approval for pwsh on arm in #273179. Robo (@deepak1556) would you be able to investigate the root cause a little here? We want to re-enable this but I don't know where to start, I'm guessing the problem is in the tree sitter library itself as I wouldn't have expected a grammar to cause an oom like that. Especially after it had seemingly already done it's work as the repro gif posted in #273177 shows that the tree sitter work is already completed.
Btw, grammars are just general purpose wasm files (compiled from tree-sitter-generated C code).
I believe the tokenizer is usually hand-written, and thus can cause arbitrary code defects (endless loops, OOM, generally being slow).
This is a major problem of treesitter.
(though I also think in this case it might even be an electron bug, as it only happens when the dev-tools are not attached)
The stacks and the nature of crash are similar to #243747 only the target process was different this time.
Running the following with --no-wasm-lazy-compilation --no-liftoff in ELECTRON_RUN_AS_NODE for the same version of V8 doesn't crash the process
import fs from "node:fs";
const buffer = fs.readFileSync(
"C:\\Users\\demohan\\github\\vscode\\node_modules\\@vscode\\tree-sitter-wasm\\wasm\\tree-sitter-powershell.wasm",
);
let module = new WebAssembly.Module(buffer);
--turbo-stats-wasm shows total memory needed to compile by the optimizing compiler is only around 2GB which should satisfy the commit memory available for the process
However, attempting the same compilation in the renderer or main process in a minimal electron app does trigger the crash. Some kind of partition allocator limit we are hitting ? I also need to confirm why it behaves different between x64 and arm64. I have a minimal repro outside vscode now, will post updates.
During loop unrolling phase when variable reducer attempts to snapshot a block with 4298 predecessors it hits this condition, merge_values_ already had a length of 281673728 at this point.
L = 281673728
zone-container#NewCapacity(4298) -> 281673728 * 2 = 563347456 (as seen on frame 9)
zone#AllocateArray<turboshaft::OpIndex> -> 563347456 * 4 = 2253389824 (> INT_MAX)
I still wasn't able to crash d8 with the same wasm file, although I was able to break on similar stack and confirmed the predecessor counts to match but not the length of the merge_values_, so what's happening ?
Running with --trace-turbo will print the turbofan IR but also print information on the function that is being compiled, this confirmed the crash was happening when compiling wasm-function#9, the generated turbo json file for this particular function was quite large (800MB) that I couldn't visualize in turbolizer
Next ran with --trace-turbo-graph --trace-turbo-filter wasm-function#9 which prints the turbofan graphs to stdout (much smaller output), couple of things stood out
Block B4 which is a loop had a switch statement with ~1800 branches
Merge Block B42591 and B42596 created as a result of this loop shows the large phi nodes that I guess eventually gets put through the variable reducer before the next phase (correct me if I am wrong here)
Looking at the same output for the crashing process, what stood out in B4 loop was the following lines which was added before each Store call
Electron doesn't setup v8::V8::EnableWebAssemblyTrapHandler for main and utility process which explains the crash on macOS.
I see that enabling this feature as a workaround it only temporarily reduces the number of variables involved via the runtime bound checks, whatever tree-sitter loop code is involved should be revisited and optimized.
bugIssue identified by VS Code Team member as probable bugchat-terminalThe run in terminal tool in chatfreeze-slow-crash-leakVS Code crashing, performance, freeze and memory leak issuesimportantIssue identified as high-priorityinsiders-releasedPatch has been released in VS Code InsidersverifiedVerification succeeded
Activity
hediet commentedon Oct 27, 2025
Btw, grammars are just general purpose wasm files (compiled from tree-sitter-generated C code).
I believe the tokenizer is usually hand-written, and thus can cause arbitrary code defects (endless loops, OOM, generally being slow).
This is a major problem of treesitter.
(though I also think in this case it might even be an electron bug, as it only happens when the dev-tools are not attached)
deepak1556 commentedon Oct 30, 2025
Crash is from thread that was attempting to compile the wasm through the optimizing compiler (turboshaft)
size value captured in the dump file at the point of crash via https://source.chromium.org/chromium/chromium/src/+/main:base/allocator/partition_allocator/src/partition_alloc/oom.cc;l=42-46 shows as 0x0 which doesn't make sense, however the process can commit around 6GB of memory
The stacks and the nature of crash are similar to #243747 only the target process was different this time.
Running the following with
--no-wasm-lazy-compilation --no-liftoffin ELECTRON_RUN_AS_NODE for the same version of V8 doesn't crash the process--turbo-stats-wasmshows total memory needed to compile by the optimizing compiler is only around 2GB which should satisfy the commit memory available for the processHowever, attempting the same compilation in the renderer or main process in a minimal electron app does trigger the crash. Some kind of partition allocator limit we are hitting ? I also need to confirm why it behaves different between x64 and arm64. I have a minimal repro outside vscode now, will post updates.
Just for fun attempted to collect
v8.zone_statsvia tracing to view in https://v8.github.io/tools/head/zone-stats/index.html howeverV8.TFTurboshaftLoopUnrollingdoesn't show up as a major consumer and the peak memory used is much different from the above table, maybe I am misreading it.deepak1556 commentedon Nov 3, 2025
More updates and seems like I have a better understanding of the issue now,
The Zone expansion callsite that was triggering the crash tripped on the following condition https://github.com/v8/v8/blob/8f0c0fc8df5b708ab508848db8ad1b04983fdcf7/src/zone/zone.cc#L175-L177
new_sizerequested was2253389824, here is a better stacktrace from debug buildDuring loop unrolling phase when variable reducer attempts to snapshot a block with 4298 predecessors it hits this condition, merge_values_ already had a length of
281673728at this point.I still wasn't able to crash d8 with the same wasm file, although I was able to break on similar stack and confirmed the predecessor counts to match but not the length of the merge_values_, so what's happening ?
Running with
--trace-turbowill print the turbofan IR but also print information on the function that is being compiled, this confirmed the crash was happening when compilingwasm-function#9, the generated turbo json file for this particular function was quite large (800MB) that I couldn't visualize in turbolizerNext ran with
--trace-turbo-graph --trace-turbo-filter wasm-function#9which prints the turbofan graphs to stdout (much smaller output), couple of things stood outBlock B4 which is a loop had a switch statement with
~1800branchesMerge Block B42591 and B42596 created as a result of this loop shows the large phi nodes that I guess eventually gets put through the variable reducer before the next phase (correct me if I am wrong here)
Looking at the same output for the crashing process, what stood out in B4 loop was the following lines which was added before each
StorecallWait a minute, this is the inlined bound checks when wasm trap handling is disabled. Ah d8 was being run with the trap handling feature enabled https://github.com/v8/v8/blob/2e3207bd63c027d2b191f4aa9b1bed408c365c87/src/d8/d8.h#L518-L520. Now when I run with
--no-wasm-lazy-compilation --no-liftoff --no-wasm-trap-handlerthe same test case does crash in d8!!To the original case, the issue was first observed in windows arm64 from the renderer process. I was able to repro the crash in both main and utility process on mac arm64. Checking back on chromium source the feature is enabled in renderer process for the following combination https://source.chromium.org/chromium/chromium/src/+/main:content/public/common/content_features.cc;l=1166-1177 which answers the differences,
Electron doesn't setup
v8::V8::EnableWebAssemblyTrapHandlerfor main and utility process which explains the crash on macOS.I see that enabling this feature as a workaround it only temporarily reduces the number of variables involved via the runtime bound checks, whatever tree-sitter loop code is involved should be revisited and optimized.
deepak1556 commentedon Nov 3, 2025
d8_repro.zip
Minimal repro with d8, also contains the turbo graph files mentioned above
Turn auto approve back on for pwsh/arm/windows
Turn auto approve back on for pwsh/arm/windows (#276954)