-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# deep-js-stacks | ||
|
||
This test case exists to show what happens to JS callstacks at around 256 frames tall. | ||
|
||
The known bug: the v8 sampling profiler only emits the _top-most_\* 256 callframes on the stack. | ||
|
||
\* Visually in the flamechart it's the bottom-most. | ||
|
||
<img width="1209" alt="top of flamechart" src="https://github.com/user-attachments/assets/0da728f5-4dc3-4412-97c0-4f197a40f37b" /> | ||
<img width="1124" alt="bottom of flamechart" src="https://github.com/user-attachments/assets/e62dbf02-dccc-418a-9fbe-488213eb2fb5" /> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// The problem manifests at a stack depth of 256, but startDemo and stall count as well. | ||
const lowBound = 248; | ||
const highBound = 256; | ||
// Additionally, worth pointing out that the named functions (call250, call252, etc) may not appear at exactly that index in the stack. For extra debugging fun. :) | ||
|
||
const output = document.getElementById('output'); | ||
let currentMaxDepth = 0; | ||
|
||
function stall() { | ||
const start = Date.now(); | ||
while (Date.now() - start < 0.5) {} | ||
} | ||
|
||
function startDemo() { | ||
const start = performance.now(); | ||
|
||
for (let maxDepth = lowBound; maxDepth <= highBound; maxDepth++) { | ||
currentMaxDepth = maxDepth; | ||
call0(); | ||
} | ||
for (let maxDepth = highBound; maxDepth >= lowBound; maxDepth--) { | ||
currentMaxDepth = maxDepth; | ||
call0(); | ||
} | ||
|
||
const measure = performance.measure( | ||
`stack-calling ${lowBound}-${highBound}`, | ||
{ start, end: performance.now() }, | ||
); | ||
|
||
output.textContent += `Total execution time: ${measure.duration.toLocaleString()}ms\n`; | ||
} | ||
|
||
// Generate all the call functions | ||
for (let i = highBound; i >= 0; i--) { | ||
window[`call${i}`] = new Function(`return function call${i}() { | ||
if (${i} > currentMaxDepth) return; | ||
if (${i} === currentMaxDepth) stall(); | ||
else call${i + 1}(); | ||
${i % 4 === 0 ? `//# sourceURL=colorcall${i}.js \n` : ''} | ||
}`)(); | ||
} | ||
|
||
startDemo(); | ||
document.querySelector('button').addEventListener('click', startDemo); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Generate icicles ~256 entries high</title> | ||
</head> | ||
<body> | ||
<button>Start Demo</button> | ||
<pre id="output"></pre> | ||
<script src="app.js"></script> | ||
</body> | ||
</html> |
This file contains 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