Details
-
Task
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
from https://github.com/mariadb-corporation/mariadb-connector-nodejs/pull/353
Each command merges its options over the connection options with a flat clone:
this.opts = Object.assign({}, connOpts, cmdParam.opts); |
connOpts is a 63-key V8 dictionary-mode object, and flat-cloning it costs far more than the key count implies (around16 µs/command locally). Using a prototype-chain merge instead:
this.opts = Object.assign(Object.create(connOpts), cmdParam.opts); |
skips the copy entirely and leaves a fast-mode object behind.
(possible because the merged object is only ever read by name, and never enumerated/spread/serialized).
this doesn't affect "string form" command, like
await connection.query('SELECT 1'); |
on command with "object form" like :
await connection.query({sql: 'SELECT 1', rowsAsArray:true}); |
Still this are what most frameworks uses, so worth this ticket.
Impact is around 1.75× throughput on small commands over local TCP, e.g. query(
{ sql: 'SELECT 1', rowsAsArray: true }): change from 38 µs to 21 µs/command.