Uploaded image for project: 'MariaDB Connector/node.js'
  1. MariaDB Connector/node.js
  2. CONJS-355

Avoid flat-cloning connection options per command

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • 3.5.4
    • 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.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.