[V8 perf] Loop callback changing is throttling
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.3k
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 283
Description
Version
v24.20.0
Platform
Windows 10
Subsystem
No response
What steps will reproduce the bug?
- Clone the repo https://github.com/AlttiRi/loop-callback-throttling-bug
- Install deps (
"sharp") - Run
demo-1.tsanddemo-2.ts
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
- BOX (~5 secs) ✅
- BOX (~5 secs) ✅
- LANCZOS (~8 secs) ✅
- LANCZOS (~8 secs) ✅
What do you see instead?
- BOX (~5 secs) ✅
- BOX (~5 secs) ✅
- LANCZOS (~30 secs) ❌
- LANCZOS (~30 secs) ❌
Additional information
I have downsample1D_V1 function (it's very unoptimized, but it works, and it's perfect for the demonstration), which executes the passed callback const weight = fn(x); billions of times (3_107_687_040 times per 1 downsample2D call).
There are 2 types of the passed callback function — lanczos3 and box:
function lanczos3(x: number): number {
if (-3 <= x && x < 3) {
return sinc(x) * sinc(x / 3);
}
return 0;
}
function sinc(x: number): number {
if (x === 0) {
return 1;
}
x = Math.PI * x;
return Math.sin(x) / x;
}
function box(x: number): number {
if (x > -0.5 && x <= 0.5) {
return 1;
}
return 0;
}
I call downsample2D multiple times with the follow callback params (demo-1.ts):
- BOX (~5 secs) ✅
- BOX (~5 secs) ✅
- LANCZOS (~30 secs) ❌
- LANCZOS (~30 secs) ❌
The first 2 calls work with the expected speed, for ~5 second.
But when the callback is changed, downsample2D works multiple times slower than expected, for ~30 seconds.
In reverse order I also face the throttling (demo-2.ts):
- LANCZOS (~8 secs) ✅
- LANCZOS (~8 secs) ✅
- BOX (~30 secs) ❌
- BOX (~30 secs) ❌
The problem appears on both Node.js (24) and Deno (2.9).
Bun (1.3/1.4) works fine:
- BOX (~5 secs) ✅
- BOX (~5 secs) ✅
- LANCZOS (~8 secs) ✅
- LANCZOS (~8 secs) ✅
Related keywords: performance v8 polymorphic inline cache
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par cloner la reproduction liée et exécuter demo-1.ts et demo-2.ts avec Node.js v24, en comparant les temps lors du changement de callbacks. Étudiez le comportement signalé du cache inline polymorphe de V8 et vérifiez le résultat avec les cas BOX et LANCZOS. Le travail est terminé lorsque le changement de callbacks ne ralentit plus les appels répétés à downsample2D par rapport aux temps attendus.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- performance
- Type d'issue
- Bug
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- Active
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100