sqlite: remove the null prototype from result rows
まだ誰も着手していません。
- 主要言語
- 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 withbetter-sqlite3.
Cons
- Semver-major.
- Rows can no longer be indexed by untrusted keys without
Object.hasOwn()—row.toStringandrow.constructorstart resolving throughObject.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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、get()、all()、iterate() の実装と、既存の run() の結果処理を探し、次に V8 API と v8::DictionaryTemplate がどのように使用されているかを確認します。issue で言及されている提案ベンチマークと動作する実装を確認します。通常のオブジェクトの挙動、共有される行の形状、パフォーマンス、semver-major に関する互換性上の懸念を評価すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, sqlite
- 領域
- backend, databases
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100