Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeCast is up to 10x slower #889

Open
gbelur opened this issue Nov 28, 2018 · 3 comments
Open

typeCast is up to 10x slower #889

gbelur opened this issue Nov 28, 2018 · 3 comments

Comments

@gbelur
Copy link

gbelur commented Nov 28, 2018

When the typeCast option is used, queries tend to run up to 10x slower under load. A perf profile shows that most of the additional time is spent in column_defintion.js obtaining the schema and table name in the code below:

const addString = function(name) {
  Object.defineProperty(ColumnDefinition.prototype, name, {
    get: function() {
      const start = this['_' + name + 'Start'];
      const end = start + this['_' + name + 'Length'];
      return StringParser.decode(
        this._buf.slice(start, end),
        this.encoding === 'binary' ? this._clientEncoding : this.encoding
      );
    }
  });
};

These fields are meant to be computed lazily, but end up getting recomputed for every field access as part of the 'wrap' function implementation that needs field.schema, field.table and field.name

function wrap(field, type, packet, encoding) {
    return {
      type: type,
      length: field.columnLength,
      db: field.schema,
      table: field.table,
      name: field.name,
      string: function() {
        return packet.readLengthCodedString(encoding);
      },
      buffer: function() {
        return packet.readLengthCodedBuffer();
      },
      geometry: function() {
        return packet.parseGeometryValue();
      }
    };
  }

Given that these fields are used for every column, can these be precomputed?

@testn
Copy link
Contributor

testn commented Nov 9, 2021

@gbelur Can you try with 2.3.3-rc0 to see if it is ok now?

@testn
Copy link
Contributor

testn commented Jun 3, 2023

I thought I fixed this already @sidorares

@sidorares
Copy link
Owner

I thought so as well
Need to test and close if can't confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants