Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[V8 perf] Loop callback changing is throttling

未關閉
#65,894 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 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?
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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

nodejs/node 的其他 Issue

查看 nodejs/node 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。