sqlite: remove the null prototype from result rows

Aperta
#65,799 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, sqlite
Ambito
backend, databases

Direzione di ricerca

Inizia individuando le implementazioni di get(), all(), iterate() e la gestione esistente dei risultati di run(), quindi leggi come vengono usati la V8 API e v8::DictionaryTemplate. Esamina i benchmark proposti e l’implementazione funzionante menzionati nell’issue. Il lavoro è completo quando sono stati valutati il comportamento degli oggetti ordinari, la forma di riga condivisa, le prestazioni e i problemi di compatibilità di semver-major.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
JavaScript
Stelle
122k
Fork
37.4k
Merge medio
4g 3h
PR unite (30g)
273

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/node

Tutte le issue di nodejs/node

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.