nodejs / nodejs/node

sqlite: remove the null prototype from result rows

オープン
#65,799 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Current behavior

Rows returned by get(), all() and iterate() are created with a null prototype. The V8 API that does this produces dictionary-mode objects, and V8 will not cache a prototype transition on a dictionary map, so every row also gets its own freshly allocated hidden class. Rows from the same statement therefore share no shape: they are slow to build, and every property access on them in user code is megamorphic.

Proposal

Drop the null prototype and build rows with v8::DictionaryTemplate, cached per statement. Rows become ordinary objects, and every row of a statement shares one hidden class.

Pros

  • all() is 10–37% faster depending on the query; reading the rows afterwards is far cheaper still.
  • Consistent with run(), which already returns an ordinary object, and with better-sqlite3.

Cons

  • Semver-major.
  • Rows can no longer be indexed by untrusted keys without Object.hasOwn()row.toString and row.constructor start resolving through Object.prototype.
  • User code comparing rows against { __proto__: null, ... } breaks.

Prototype pollution is not a concern either way: rows are built by defining own properties directly, so a __proto__ column is an own property and never reaches Object.prototype.

I have benchmarks and a working implementation if there is interest.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、get()、all()、iterate() の実装と、既存の run() の結果処理を探し、次に V8 API と v8::DictionaryTemplate がどのように使用されているかを確認します。issue で言及されている提案ベンチマークと動作する実装を確認します。通常のオブジェクトの挙動、共有される行の形状、パフォーマンス、semver-major に関する互換性上の懸念を評価すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, sqlite
領域
backend, databases
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。