[V8 perf] Loop callback changing is throttling
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 需要釐清
- 活躍度
- 活躍
- 技術堆疊
- javascript
- 領域
- performance
研究方向
首先複製連結的重現程式,並在 Node.js v24 下執行 demo-1.ts 和 demo-2.ts,比較切換 callback 時的耗時。調查報告中的 V8 多型 inline cache 行為,並針對 BOX 和 LANCZOS 情況驗證結果。當變更 callback 不再導致重複的 downsample2D 呼叫相較於預期耗時變慢時,即視為完成。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- JavaScript
- 星號
- 122k
- 分支
- 38.4k
- 平均合併
- 3 天 22 小時
- 30 天內合併 PR
- 273
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
build / doc: missing platform and toolchain info for `linux-x64-musl`可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉alpine build doc
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already exist可能已有人在做 @Sepandard 於 10 天前認領。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
Stream.prototype.forEach will block in first promise in queue before read more chunk可能已有人在做 @mmustafasenoglu 於 11 天前認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
`TextEncoder.encodeInto()` underfills the destination for some non-ASCII text可能已有人在做 @XadillaX 於 24 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
nodejs/node#65994 · 2 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 80/100
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
NationalSecurityAgency/skills-service#4052 ·
維護者通常 1 天內回覆
-
documentation
難度 1/5 1 小時以內 新手友好度 88/100
githubnext/gh-aw-workshop#4251 ·
維護者通常 1 天內回覆
-
customer-support needs-triage Platform(Default)
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
Leonxlnx/taste-skill#129 ·
維護者通常 1 天內回覆