Skip to content

[Improvement] Performance improvements: Performance of the model query path compared to query builders (same queries, ~2.7x–3.8x gap) #18551

Description

@ramazansancar

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Feature Description

Describe the feature you'd like to see implemented

Hi, are there any plans to improve performance on the query/result path in Sequelize?

We have a Node.js API built with Express, PostgreSQL as the database and Redis for caching. Sequelize 6 is our ORM. During load testing we profiled the API processes, and Sequelize itself (plus the lodash calls coming from it) took roughly 30–39% of the busy CPU time. The database was not the bottleneck; the API processes were CPU-bound.

To make sure this wasn't caused by how we use it, we ran the same four queries through Sequelize models, drizzle-orm, Kysely and plain pg, against the same database and returning the same rows. The numbers are below. Sequelize models came out about 2.7x slower than drizzle and 3.8x slower than Kysely, mostly because of client-side CPU per query (about 0.39 ms vs 0.10–0.14 ms).

We don't have a specific API change in mind. Mainly we'd like to know:

  • whether query/result-path performance is something you're working on (for v6 or v7),
  • whether there are options we might be missing that reduce this overhead (we already use attributes everywhere and through: { attributes: [] } on many-to-many includes).

Setup

  • Node.js 24, PostgreSQL 13, Sequelize 6.37.8, pg 8.23.1, drizzle-orm 0.45.4, Kysely 0.29.6
  • Same machine and same database (~1.6 GB of generated data), same pool size (12), 12 queries in flight
  • Each side in its own process, 20 s per run, 3 rounds with the sides interleaved; we report the median
  • All sides return identical results (checked with a fingerprint of the returned rows)
  • We ran the whole benchmark again on another day and got the same ratios

Query mix (35 / 25 / 25 / 15 %):

// 1. find by primary key with a many-to-many include
User.findByPk(id, {
  attributes: [/* 7 columns */],
  include: [{ model: Role, as: 'roles', attributes: [/* 4 columns */], through: { attributes: [] } }],
});

// 2. list with a filtered one-to-many include, two-column order, limit
Item.findAll({
  attributes: [/* 5 columns */],
  where: { isActive: true, isPublic: true },
  include: [{ model: ItemTranslation, as: 'translations', attributes: ['name'], where: { language: 'en' }, required: false }],
  order: [['displayOrder', 'ASC NULLS LAST'], ['createdAt', 'DESC']],
  limit: 40,
});

// 3. simple list: where + order + limit, no include
Message.findAll({ attributes: [/* 5 columns */], where: { userId: id }, order: [['createdAt', 'DESC']], limit: 20 });

// 4. count with an OR
Link.count({ where: { status: 'accepted', [Op.or]: [{ userId: id }, { otherId: id }] } });

Results: same four queries

Sequelize models drizzle-orm Kysely plain pg
Queries / s (median of 3) 2,738 7,255 10,409 21,651
Relative to Sequelize 1x 2.65x 3.80x 7.91x
Client CPU per query 0.39 ms 0.14 ms 0.10 ms 0.05 ms
Latency p50 / p95 (avg of the 4 queries) 3.9 / 7.6 ms 1.5 / 2.7 ms 1.1 / 1.8 ms 0.5 / 0.8 ms
Process RSS 219 MB 178 MB 150 MB 133 MB

Results: raw SQL path (same SQL text, separate run)

plain pg sequelize.query(sql, { type: QueryTypes.SELECT })
Queries / s (median of 3) 14,704 10,243
Client CPU per query 0.070 ms 0.101 ms

Even with raw SQL, Sequelize adds about 30% client CPU on top of the driver.

Profile under load (3 API processes, steady state, share of busy CPU time)

Component Share
sequelize ~30%
lodash (mostly called from sequelize) ~9%
sequelize-pool ~0.5%

Describe why you would like this feature to be added to Sequelize

The overhead is in the core path that every query goes through: building options, generating SQL, and building instances and includes from the result. A separate package can't really change that. For us the alternative is to move our hottest queries to a query builder, which means running two data layers side by side. We'd rather stay on Sequelize if this gap can get smaller.

Is this feature dialect-specific?

  • No. This feature is relevant to Sequelize as a whole.
  • Yes. This feature only applies to the following dialect(s):

(We only measured on PostgreSQL, but the overhead is on the JavaScript side.)

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.


Activity

  1. added
    pending-approval
    on Oct 12, 2026
  2. SippieCup commented on Oct 19, 2026

    @SippieCup
    Contributor

    7v has a completely rewritten query builder and hydration engine which in worse case is (R*C)^2 faster, in reality you can see hydration is 3x more CPU efficient and gets on average 70% faster across queries, for queries like yours, I can see it being even higher.

    See #18051

    I would run your benchmarks against v7 to see how it runs.

  3. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    7v has a completely rewritten query builder and hydration engine which in worse case is (R*C)^2 faster, in reality you can see hydration is 3x more CPU efficient and gets on average 70% faster across queries, for queries like yours, I can see it being even higher.

    See #18051

    I would run your benchmarks against v7 to see how it runs.

    Hi @SippieCup,
    I'll be running a benchmark test with v7 within a week and adding the results here.

    I have a quick question: when do you plan to release v7?

    Thanks.

  4. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    Thanks @SippieCup. We ran the same benchmark against v7 and also went through a few older versions to see how things changed over time.

    In our case @sequelize/[email protected] turned out about 20% slower than [email protected] on the model path. Alphas 43, 46, 47 and 48 all give the same numbers, so for our queries we can't see a difference from #18051. That makes sense to us: our results are small (40 rows at most, one level of include), and that PR mostly helps hydration of big result sets.

    We profiled v7 and most of the gap comes from two small places. When we changed both of them locally, v7 was as fast as v6. Details below.

    Setup

    Mostly the same as in the first post. The database is PostgreSQL 17 now (it was 13 before), but that didn't change the client-side numbers: the app's own v6 models gave 2,786 q/s now and 2,738 q/s last time.

    • Node.js 24.21.0, PostgreSQL 17.11, pg 8.23.1 on every side
    • i5-13500H (12 cores / 16 threads), Docker Desktop on WSL2, machine otherwise idle during the runs
    • ~1.7 GB of generated data (11.5k users, ~120k rows in the messages table)
    • Pool size 12, 12 queries in flight, one process per side
    • 20 s per run, 3 rounds, sides interleaved inside each round, we report the median. Rounds were within ±3% of each other.
    • Every side returns the same rows. We compare a fingerprint of the first result and a hash of the full results for 30 users plus the whole list from query 2.

    To keep the comparison fair, v6 and v7 load the same model file: 7 models with only the columns the queries use, the same associations, and the same through.scope on the many-to-many. So the only thing that changes between them is the library. The queries are the four from the first post (35/25/25/15 mix).

    Model definitions (shared by v6 and v7)
    // called with (sequelize, { DataTypes, Op, literal }) from either 'sequelize' or '@sequelize/core'
    export function defineModels(sequelize, { DataTypes, Op, literal }) {
      const opts = (tableName) => ({ tableName, timestamps: false });
      const User = sequelize.define('User', {
        id: { type: DataTypes.UUID, primaryKey: true },
        email: DataTypes.TEXT,
        username: DataTypes.STRING,
        firstName: DataTypes.STRING,
        lastName: DataTypes.STRING,
        organizationId: DataTypes.UUID,
        preferredLanguage: DataTypes.STRING,
      }, opts('Users'));
      const Role = sequelize.define('Role', {
        id: { type: DataTypes.UUID, primaryKey: true },
        key: DataTypes.STRING,
        name: DataTypes.STRING,
        priority: DataTypes.INTEGER,
      }, opts('Roles'));
      const UserRole = sequelize.define('UserRole', {
        id: { type: DataTypes.UUID, primaryKey: true },
        userId: DataTypes.UUID,
        roleId: DataTypes.UUID,
        isActive: DataTypes.BOOLEAN,
        expiresAt: DataTypes.DATE,
      }, opts('UserRoles'));
      const Item = sequelize.define('Item', {
        id: { type: DataTypes.UUID, primaryKey: true },
        type: DataTypes.STRING,
        isPublic: DataTypes.BOOLEAN,
        isActive: DataTypes.BOOLEAN,
        displayOrder: DataTypes.INTEGER,
        createdAt: DataTypes.DATE,
      }, opts('Items'));
      const ItemTranslation = sequelize.define('ItemTranslation', {
        id: { type: DataTypes.UUID, primaryKey: true },
        itemId: DataTypes.UUID,
        language: DataTypes.STRING,
        name: DataTypes.STRING,
      }, opts('ItemTranslations'));
      const Message = sequelize.define('Message', {
        id: { type: DataTypes.UUID, primaryKey: true },
        userId: DataTypes.UUID,
        type: DataTypes.STRING,
        title: DataTypes.STRING,
        isRead: DataTypes.BOOLEAN,
        createdAt: DataTypes.DATE,
      }, opts('Messages'));
      const Link = sequelize.define('Link', {
        id: { type: DataTypes.UUID, primaryKey: true },
        userId: DataTypes.UUID,
        otherId: DataTypes.UUID,
        status: DataTypes.STRING,
      }, opts('Links'));
    
      User.belongsToMany(Role, {
        through: {
          model: UserRole,
          unique: false,
          scope: {
            isActive: true,
            [Op.or]: [{ expiresAt: null }, { expiresAt: { [Op.gt]: literal('NOW()') } }],
          },
        },
        foreignKey: 'userId', otherKey: 'roleId', as: 'roles',
      });
      Item.hasMany(ItemTranslation, { as: 'translations', foreignKey: 'itemId' });
    
      return { User, Role, UserRole, Item, ItemTranslation, Message, Link };
    }

    v6 is created with new Sequelize(db, user, pass, { dialect: 'postgres', host, port, logging: false, pool: { max: 12, min: 2 } }),
    v7 with new Sequelize({ dialect: PostgresDialect, host, port, user, password, database, logging: false, pool: { max: 12, min: 2 } }).

    Model path: v6 and v7 versions

    All in one run, each version installed in its own folder.

    Version Released Queries/s Client CPU / query p50 / p95 (avg of 4 queries)
    sequelize 6.28.0 2022-12 3,316 0.322 ms 3.22 / 6.30 ms
    sequelize 6.32.1 2023-06 3,303 0.324 ms 3.23 / 6.32 ms
    sequelize 6.35.2 2023-12 3,257 0.328 ms 3.28 / 6.40 ms
    sequelize 6.37.7 2025-03 3,217 0.332 ms 3.33 / 6.49 ms
    sequelize 6.37.8 2026-03 3,228 0.331 ms 3.32 / 6.48 ms
    @sequelize/core 7.0.0-alpha.43 2024-10 2,578 0.417 ms 4.17 / 8.14 ms
    @sequelize/core 7.0.0-alpha.46 2025-03 2,576 0.417 ms 4.19 / 8.15 ms
    @sequelize/core 7.0.0-alpha.47 2025-10 2,586 0.417 ms 4.16 / 8.14 ms
    @sequelize/core 7.0.0-alpha.48 2026-02 2,590 0.417 ms 4.16 / 8.12 ms

    For reference, from the same run with the same queries:

    Version Queries/s Client CPU / query
    our app's own models (all columns, hooks, scopes) sequelize 6.37.8 2,910 0.365 ms
    drizzle-orm 0.40.1 8,389 0.124 ms
    drizzle-orm 0.44.7 7,787 0.134 ms
    drizzle-orm 0.45.4 7,662 0.136 ms
    drizzle-orm 1.0.0-rc.4 7,816 0.133 ms
    kysely 0.28.18 10,590 0.100 ms
    kysely 0.29.7 10,558 0.100 ms
    kysely 0.30.0-beta.2 10,632 0.099 ms
    mikro-orm 6.6.17 902 2.026 ms
    mikro-orm 7.2.5 1,378 0.923 ms
    plain pg 8.23.1 22,766 0.045 ms

    The v7 slowdown is spread over all four queries, including the two that have no include at all. So it isn't only hydration. The process is CPU-bound with 12 queries in flight, so latency here mostly reflects CPU time per query.

    Query (p50 / p95 / p99 ms) sequelize 6.37.8 @sequelize/core alpha.48
    1. findByPk + many-to-many include 3.40 / 6.71 / 7.91 4.17 / 8.29 / 9.86
    2. findAll + filtered hasMany include, order, limit 40 3.62 / 7.11 / 8.41 4.50 / 8.88 / 10.44
    3. findAll, where + order + limit 20, no include 3.22 / 6.23 / 7.53 3.98 / 7.71 / 9.44
    4. count with Op.or 3.19 / 6.17 / 7.42 3.93 / 7.66 / 9.23

    One SQL difference we noticed: for query 1, v7 wraps the user in a subquery with ORDER BY "User"."id" LIMIT 1 before joining the roles. v6 does a flat join. It returns the same rows and doesn't seem to matter for the DB here, but it's different.

    Query 1 SQL, v6 vs v7

    v6:

    SELECT "User"."id", "User"."email", ..., "roles"."id" AS "roles.id", "roles"."key" AS "roles.key", ...
    FROM "Users" AS "User"
    LEFT OUTER JOIN ( "UserRoles" AS "roles->UserRole"
      INNER JOIN "Roles" AS "roles" ON "roles"."id" = "roles->UserRole"."roleId"
      AND ("roles->UserRole"."expiresAt" IS NULL OR "roles->UserRole"."expiresAt" > NOW())
      AND "roles->UserRole"."isActive" = true) ON "User"."id" = "roles->UserRole"."userId"
    WHERE "User"."id" = '...';

    v7 alpha.48:

    SELECT "User".*, "roles"."id" AS "roles.id", "roles"."key" AS "roles.key", ...
    FROM (SELECT "User"."id", "User"."email", ... FROM "Users" AS "User"
          WHERE "User"."id" = '...' ORDER BY "User"."id" LIMIT 1) AS "User"
    LEFT OUTER JOIN ( "UserRoles" AS "roles->UserRole"
      INNER JOIN "Roles" AS "roles" ON "roles"."id" = "roles->UserRole"."roleId"
      AND ("roles->UserRole"."expiresAt" IS NULL OR "roles->UserRole"."expiresAt" > NOW())
      AND "roles->UserRole"."isActive" = true) ON "User"."id" = "roles->UserRole"."userId";

    What the profile shows

    We took a CPU profile (node --cpu-prof) of v6 and v7 doing the same 20 s run and counted self time per query in the steady part, ignoring startup.

    Self time per query (µs) sequelize 6.37.8 @sequelize/core alpha.48 alpha.48 + isModelStatic fix
    sequelize / @sequelize/core 169 180 175
    lodash 48 70 70
    Node internals (node:internal/*, in v7 mostly the module loader) 6 41 7
    @sequelize/utils + @sequelize/postgres n/a 10 10
    pg + pg-protocol 17 18 16
    native / GC / rest 74 71 68
    total busy 314 390 346

    So the core code itself costs about the same in both versions. The difference comes from two things: the module loader showing up on the hot path, and more lodash work.

    1. isModelStatic calls require() every time. In packages/core/src/utils/model-utils.ts:

    export function isModelStatic<M extends Model>(val: any): val is ModelStatic<M> {
      // TODO: temporary workaround due to cyclic import. Should not be necessary once Model is fully migrated to TypeScript.
      const { Model: TmpModel } = require('../model');
    
      return typeof val === 'function' && val.prototype instanceof TmpModel;
    }

    It gets called many times per query, for example selectQuery → getQueryOrders → quote → isModelStatic. Even when the module is cached, require still goes through resolution, and that's where internalModuleStat, lstat and package_json_reader come from in the profile. In a small loop one call takes about 850–975 ns. The same instanceof check inline takes about 10 ns. It's the same on main today.

    2. The Model constructor deep-copies the options for every instance. In alpha.48 lib/model.js:

    this._options = (0, import_omit.default)(options, ["comesFromDatabase"]);

    lodash omit clones deeply, and this runs once per row. That's about 29 µs per query for us (query 2 builds 40+ instances). In v6 the same line is just this._options = options;.

    There's also rejectInvalidOptions calling lodash pickBy on every call (~11 µs per query). We didn't touch that one.

    Trying the two fixes

    We changed the alpha.48 build output in a separate folder and ran it next to unpatched v6 and v7:

     // lib/utils/model-utils.js
    +let TmpModel;
     function isModelStatic(val) {
    -  const { Model: TmpModel } = require("../model");
    +  TmpModel ??= require("../model").Model;
       return typeof val === "function" && val.prototype instanceof TmpModel;
     }
     // lib/model.js, Model constructor
    -    this._options = (0, import_omit.default)(options, ["comesFromDatabase"]);
    +    const { comesFromDatabase: _cfd, ...ownOptions } = options;
    +    this._options = ownOptions;

    The second one is a shallow copy instead of a deep one, so it's probably not a drop-in fix. We only wanted to see how much it costs.

    Same run, 3 rounds Queries/s Client CPU / query Q1 p50 Q2 p50 Q3 p50 Q4 p50
    sequelize 6.37.8 3,189 0.335 ms 3.40 3.62 3.22 3.19
    @sequelize/core alpha.48 2,591 0.416 ms 4.17 4.50 3.98 3.93
    + isModelStatic fix 2,886 (+11%) 0.373 ms 3.73 4.05 3.55 3.51
    + no omit in the constructor 3,161 (+22%) 0.341 ms 3.41 3.65 3.23 3.19

    With both changes alpha.48 lands right where v6 is (3,161 vs 3,189). The isModelStatic one looks safe to us. We'd be glad to send a PR for it if you want.

    Raw SQL path

    Same SQL text on every side, sequelize.query(sql, { type: QueryTypes.SELECT, bind }). This ran in a separate container (Node 24.22.0), so the absolute numbers don't line up with the tables above.

    Queries/s vs pg Client CPU / query p50 / p95
    pg 8.23.1 14,574 1.00x 0.071 ms 0.75 / 1.18 ms
    pg-native 3.9.1 14,986 1.03x 0.068 ms 0.75 / 1.09 ms
    postgres (postgres.js) 3.4.9 18,354 1.26x 0.065 ms 0.59 / 0.92 ms
    sequelize 6.37.8 over pg 10,474 0.72x 0.099 ms 1.06 / 1.82 ms
    sequelize 6.37.8 over pg-native 11,043 0.76x 0.093 ms 1.04 / 1.42 ms
    @sequelize/core alpha.48 over pg 14,010 0.96x 0.075 ms 0.78 / 1.25 ms
    @sequelize/core alpha.48 over pg-native 13,767 0.94x 0.075 ms 0.83 / 1.16 ms

    This is a big improvement in v7, it's very close to the driver now. One thing though: v7 gives back timestamptz columns as strings in raw queries ("2026-10-19 08:20:00.03+00"), while pg and v6 give Date objects. So some of this comes from not parsing dates. We guess that's on purpose, just mentioning it.

    If it helps, we can share the full benchmark script, or run it against a build from main or a branch.

  5. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    I will experiment with further performance improvements and share my findings in the comments. This may take some time. Thank you for your understanding.

  6. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    A follow-up with more data. We took the hot spots from the profile, turned each one into a small patch, and measured every patch alone and in every combination, for both v6 and v7.

    First, a correction to my last comment: the table sizes were wrong. I took them from our generator's counters, not from the tables. The real numbers are about 21.3k users, 23.8k user-role rows and ~497k rows in the messages table. All sides ran on the same data, so the results don't change.

    How we ran it

    Same four queries, same machine and setup as before (Node.js 24.21.0, PostgreSQL 17.11, pg 8.23.1, pool 12, 12 in flight, 20 s per run). Each patch combination is installed in its own folder and patched in the published build output (lib/), so nothing else changes between sides. 3 rounds, sides interleaved, median reported. Rounds were within ±3%. We also checked before every round that nothing else on the host (Windows Defender in particular) was using the CPU. Every side returned identical results.

    Baselines: @sequelize/[email protected] 2,439 q/s and [email protected] 3,059 q/s, with the same model definitions.

    v7: isModelStatic calls require() on every call

     // lib/utils/model-utils.js
    +let TmpModel;
     function isModelStatic(val) {
    -  const { Model: TmpModel } = require("../model");
    +  TmpModel ??= require("../model").Model;
       return typeof val === "function" && val.prototype instanceof TmpModel;
     }

    +12.8% on average (+11.3% to +15.5% depending on what else is applied). Same behavior, just no module resolution on the hot path.

    v7: the Model constructor deep-clones its options per instance

     // lib/model.js, Model constructor
    -    this._options = (0, import_omit.default)(options, ["comesFromDatabase"]);
    +    const { comesFromDatabase: _cfd, ...ownOptions } = options;
    +    this._options = ownOptions;

    +10.3% on average (+8.8% to +13.6%). lodash omit clones deeply and this runs once per row. v6 just keeps a reference (this._options = options). We're not 100% sure nothing relies on _options being a deep copy, so this one needs a closer look.

    v7: rejectInvalidOptions uses pickBy on every call

     // lib/utils/check.js
    -  const receivedOptionNames = Object.keys(
    -    (0, import_pickBy.default)(receivedOptions, (value) => value !== void 0 && value !== false)
    -  );
    +  const receivedOptionNames = [];
    +  for (const key in receivedOptions) {
    +    const value = receivedOptions[key];
    +    if (value !== void 0 && value !== false) receivedOptionNames.push(key);
    +  }

    +5.3% on average (+3.9% to +7.7%). Same result, no intermediate object.

    v6: esbuild's object spread helpers

    The v6 build turns every { ...a } into __spreadValues / __defNormalProp calls. These two helpers took about 24 µs per query in our profile. As an experiment we replaced the helper in the build output with Object.assign (36 files):

    -var __spreadValues = (a, b) => {
    -  for (var prop in b || (b = {}))
    -    if (__hasOwnProp.call(b, prop))
    -      __defNormalProp(a, prop, b[prop]);
    -  ...
    -  return a;
    -};
    +var __spreadValues = (a, b) => Object.assign(a, b);

    +10.0% on average (+9.0% to +11.1%). The proper fix would be a newer esbuild target, so the spread stays native (v7's build already does this). There's one small difference from the helper: Object.assign calls setters if a key exists on the target's prototype. For plain option objects that shouldn't matter.

    Experiments that change behavior (cost only, not proposals)

    • v6 run() creates new Error() for every query (dialects/postgres/query.js, to keep the call-site stack for DB errors). Without it: +7.0% (+5.8% to +8.2%). That stack is useful, so this is just to show what it costs. Capturing it lazily isn't possible, but maybe it could be opt-out.
    • options = cloneDeep(options) in findAll / findOne / count / … (both versions, 10 places in model.js). A shallow copy instead: +3.2% in both v6 and v7. This isn't safe as it is, because the caller's include objects would get mutated. It just shows the defensive copy isn't where most of the time goes.

    raw: true

    Not a patch, just for scale. Our queries with raw: true (query 1 via findAll, because findByPk + raw only keeps the first joined row):

    Queries/s vs its baseline Client CPU / query p50 / p95 / p99 ms
    v6 6.37.8 4,716 +54% 0.226 ms 2.19 / 4.38 / 5.40
    v6 + spread helper fix 4,885 +60% 0.218 ms 2.10 / 4.22 / 5.27
    v7 alpha.48 4,194 +72% 0.256 ms 2.46 / 4.94 / 6.14
    v7 + isModelStatic + omit + rio 5,616 +130% 0.191 ms 1.80 / 3.64 / 4.67

    So building model instances is still the biggest single cost on both versions.

    All combinations

    Latency columns below are the average of the four queries' p50 / p95 / p99 (12 in flight). The patches don't interact much: pairs land close to the sum of the single effects (v7 isModelStatic + omit +23.3% vs +21.7% summed; v6 stack + spread +16.9% vs +17.8%).

    v7 alpha.48 Queries/s vs baseline Client CPU / query p50 / p95 / p99 ms
    baseline 2,439 — 0.443 ms 4.34 / 8.70 / 10.94
    isModelStatic 2,716 +11.4% 0.398 ms 3.92 / 7.76 / 9.61
    omit 2,691 +10.3% 0.401 ms 3.97 / 7.78 / 9.54
    rio 2,545 +4.3% 0.424 ms 4.21 / 8.27 / 10.19
    isModelStatic + omit 3,007 +23.3% 0.358 ms 3.53 / 6.96 / 8.57
    isModelStatic + rio 2,904 +19.1% 0.371 ms 3.68 / 7.24 / 9.03
    omit + rio 2,804 +15.0% 0.384 ms 3.78 / 7.47 / 9.20
    isModelStatic + omit + rio 3,187 +30.7% 0.338 ms 3.32 / 6.57 / 8.18
    all three + shallow clone (experiment) 3,337 +36.8% 0.323 ms 3.18 / 6.28 / 7.82
    v6 6.37.8 Queries/s vs baseline Client CPU / query p50 / p95 / p99 ms
    baseline 3,059 — 0.350 ms 3.48 / 6.83 / 8.52
    spread helper fix 3,379 +10.5% 0.317 ms 3.14 / 6.15 / 7.52
    no new Error() per query (experiment) 3,282 +7.3% 0.326 ms 3.23 / 6.36 / 7.84
    spread + no new Error() 3,576 +16.9% 0.300 ms 2.95 / 5.82 / 7.22
    spread + no new Error() + shallow clone 3,741 +22.3% 0.287 ms 2.82 / 5.56 / 6.88

    Per query, for the baselines and the best safe combinations (p50 / p95 / p99 ms):

    Query (p50 / p95 / p99 ms) v7 baseline v7 isModelStatic + omit + rio v7 isModelStatic + omit + rio + raw: true v6 baseline v6 spread v6 baseline + raw: true
    1. findByPk + many-to-many include 4.37 / 8.81 / 10.94 3.35 / 6.75 / 8.34 1.82 / 3.78 / 4.76 3.51 / 6.95 / 8.55 3.20 / 6.35 / 7.77 2.23 / 4.56 / 5.63
    2. findAll + hasMany include, order, limit 40 4.73 / 9.55 / 11.74 3.61 / 7.18 / 8.86 1.95 / 4.05 / 5.07 3.76 / 7.46 / 9.25 3.36 / 6.70 / 8.01 2.33 / 4.80 / 5.85
    3. findAll, no include 4.18 / 8.16 / 10.43 3.17 / 6.15 / 7.74 1.71 / 3.37 / 4.45 3.33 / 6.46 / 8.15 3.00 / 5.79 / 7.21 2.11 / 4.07 / 5.13
    4. count with Op.or 4.11 / 8.15 / 10.48 3.15 / 6.24 / 7.92 1.72 / 3.38 / 4.39 3.31 / 6.43 / 8.17 2.98 / 5.77 / 7.11 2.10 / 4.07 / 5.08
    Every combination: q/s, client CPU, latency (3 rounds each)

    Latency is the average of the four queries' p50 / p95 / p99. With 12 queries in flight and a CPU-bound process, latency mostly follows CPU per query.

    Side Rounds (q/s) Median q/s vs baseline Client CPU / query p50 / p95 / p99 ms (avg of 4 queries) RSS
    v7 baseline 2,408 / 2,466 / 2,439 2,439 +0.0% 0.443 ms 4.34 / 8.70 / 10.94 172 MB
    v7 clone 2,531 / 2,529 / 2,568 2,531 +3.8% 0.427 ms 4.21 / 8.24 / 10.35 171 MB
    v7 rio 2,570 / 2,525 / 2,545 2,545 +4.3% 0.424 ms 4.21 / 8.27 / 10.19 172 MB
    v7 rio + clone 2,678 / 2,639 / 2,630 2,639 +8.2% 0.408 ms 4.05 / 7.94 / 9.83 172 MB
    v7 omit 2,669 / 2,698 / 2,691 2,691 +10.3% 0.401 ms 3.97 / 7.78 / 9.54 168 MB
    v7 isModelStatic 2,716 / 2,695 / 2,749 2,716 +11.4% 0.398 ms 3.92 / 7.76 / 9.61 171 MB
    v7 omit + clone 2,739 / 2,753 / 2,763 2,753 +12.9% 0.392 ms 3.86 / 7.57 / 9.43 168 MB
    v7 omit + rio 2,804 / 2,792 / 2,836 2,804 +15.0% 0.384 ms 3.78 / 7.47 / 9.20 168 MB
    v7 isModelStatic + clone 2,879 / 2,829 / 2,810 2,829 +16.0% 0.382 ms 3.75 / 7.44 / 9.53 171 MB
    v7 omit + rio + clone 2,857 / 2,890 / 2,915 2,890 +18.5% 0.373 ms 3.67 / 7.25 / 9.04 167 MB
    v7 isModelStatic + rio 2,904 / 2,895 / 2,904 2,904 +19.1% 0.371 ms 3.68 / 7.24 / 9.03 170 MB
    v7 isModelStatic + rio + clone 2,954 / 2,930 / 2,938 2,938 +20.5% 0.367 ms 3.62 / 7.15 / 8.99 170 MB
    v7 isModelStatic + omit 3,007 / 3,030 / 2,898 3,007 +23.3% 0.358 ms 3.53 / 6.96 / 8.57 166 MB
    v7 isModelStatic + omit + clone 3,099 / 3,161 / 3,015 3,099 +27.1% 0.348 ms 3.42 / 6.76 / 8.42 167 MB
    v7 isModelStatic + omit + rio 3,187 / 3,188 / 3,112 3,187 +30.7% 0.338 ms 3.32 / 6.57 / 8.18 167 MB
    v7 isModelStatic + omit + rio + clone 3,337 / 3,323 / 3,352 3,337 +36.8% 0.323 ms 3.18 / 6.28 / 7.82 168 MB
    v7 baseline + raw: true 4,194 / 4,155 / 4,242 4,194 +72.0% 0.256 ms 2.46 / 4.94 / 6.14 162 MB
    v7 isModelStatic + omit + rio + raw: true 5,616 / 5,552 / 5,628 5,616 +130.3% 0.191 ms 1.80 / 3.64 / 4.67 162 MB
    v6 baseline 2,937 / 3,059 / 3,065 3,059 +0.0% 0.350 ms 3.48 / 6.83 / 8.52 152 MB
    v6 clone 2,979 / 3,170 / 3,161 3,161 +3.3% 0.339 ms 3.37 / 6.62 / 8.21 152 MB
    v6 stack 3,176 / 3,282 / 3,303 3,282 +7.3% 0.326 ms 3.23 / 6.36 / 7.84 152 MB
    v6 stack + clone 3,293 / 3,379 / 3,367 3,367 +10.1% 0.318 ms 3.14 / 6.18 / 7.70 153 MB
    v6 spread 3,221 / 3,383 / 3,379 3,379 +10.5% 0.317 ms 3.14 / 6.15 / 7.52 152 MB
    v6 spread + clone 3,291 / 3,458 / 3,476 3,458 +13.0% 0.310 ms 3.07 / 6.02 / 7.52 152 MB
    v6 stack + spread 3,450 / 3,576 / 3,585 3,576 +16.9% 0.300 ms 2.95 / 5.82 / 7.22 151 MB
    v6 stack + spread + clone 3,568 / 3,747 / 3,741 3,741 +22.3% 0.287 ms 2.82 / 5.56 / 6.88 152 MB
    v6 baseline + raw: true 4,688 / 4,716 / 4,727 4,716 +54.2% 0.226 ms 2.19 / 4.38 / 5.40 148 MB
    v6 spread + raw: true 4,885 / 4,929 / 4,805 4,885 +59.7% 0.218 ms 2.10 / 4.22 / 5.27 148 MB
    app models (6.37.8) 2,635 / 2,746 / 2,797 2,746 — 0.387 ms 3.90 / 7.62 / 9.23 219 MB
    plain pg (reference) 20,286 / 21,779 / 22,155 21,779 — 0.047 ms 0.51 / 0.79 / 1.10 132 MB

    One more thing: v5 vs v6

    In another run (same queries and model definitions, Node 24.22.0 in a separate container), [email protected] did 3,407 q/s and [email protected] did 2,794 q/s, so v5 is about 18% faster.

    Same models, separate run Queries/s Client CPU / query p50 / p95 / p99 ms
    sequelize 5.22.5 3,407 0.320 ms 3.21 / 5.22 / 7.92
    sequelize 6.37.8 2,794 0.385 ms 3.65 / 7.57 / 10.96

    Across v6 itself the drop is small (6.28.0 → 6.37.8 is about −3%), so most of it seems to be from the v5 → v6 move. Our guess is that the esbuild spread helpers are part of it, since v5 shipped untranspiled JS. We haven't verified that.

    The three v7 changes (isModelStatic, the constructor omit, rejectInvalidOptions) look safe to us, and together they take v7 past v6. We can open PRs for them if you'd like, maybe starting with isModelStatic, which is a one-line change.

  7. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    One more, for context. While we were at it we ran the same four queries through every other ORM, query builder and SQL library we could find, plus a few other databases. It's not a Sequelize problem as such, but it shows where Sequelize sits next to the alternatives, and it might be useful when you look at the hot paths.

    Same setup and data as in the last comment, and every side returned the same rows. One thing to keep in mind: each table is a separate run, and some ran inside our API container (Node 24.21.0) while others ran in their own container (Node 24.22.0). So it's better to compare rows within a table rather than across tables. Latency is the average of the four queries.

    ORMs and query libraries on PostgreSQL 17

    Library Version Queries/s vs Sequelize Client CPU / query p50 / p95 / p99 ms RSS
    plain pg (ids only) pg 8.23.1 22,298 7.32x 0.046 ms 0.50 / 0.77 / 1.09 132 MB
    postgres.js (tagged templates) 3.4.9 20,440 6.71x 0.063 ms 0.52 / 0.86 / 2.36 149 MB
    pg-promise 12.7.1 14,456 4.75x 0.072 ms 0.76 / 1.26 / 1.67 140 MB
    @databases/pg 6.1.0 13,239 4.35x 0.079 ms 0.83 / 1.36 / 1.88 150 MB
    Kysely 0.29.7 10,250 3.37x 0.103 ms 1.08 / 1.82 / 2.46 150 MB
    Slonik 49.11.0 10,221 3.36x 0.102 ms 1.08 / 1.64 / 2.21 154 MB
    drizzle-orm 0.45.4 7,493 2.46x 0.139 ms 1.45 / 2.63 / 3.29 180 MB
    Orchid ORM 1.78.27 6,776 2.22x 0.157 ms 1.59 / 2.83 / 4.01 155 MB
    Zapatos 6.6.1 6,203 2.04x 0.159 ms 1.75 / 2.96 / 3.70 140 MB
    Prisma (adapter-pg) 7.10.1 3,461 1.14x 0.341 ms 2.66 / 5.60 / 7.48 176 MB
    Objection.js (Knex 3.3.0) 4.2.0 3,448 1.13x 0.316 ms 3.02 / 6.01 / 7.58 158 MB
    Sequelize 6.37.8 3,046 1.00x 0.351 ms 3.50 / 6.86 / 8.35 153 MB
    MikroORM 7.2.5 1,292 0.42x 0.981 ms 8.21 / 16.30 / 21.88 189 MB

    Plain pg here only selects the id columns (it's the reference from our earlier runs). The SQL libraries (postgres.js, pg-promise, @databases/pg, Slonik) select the same columns as the ORMs. Prisma 7 uses @prisma/adapter-pg with the new query compiler. For Objection, MikroORM and TypeORM the user-role join row is its own model, since their many-to-many filters can't see the join table.

    TypeORM and Knex were measured in a different run, so here they are with the ones they shared a run with:

    Library Version Queries/s vs Sequelize Client CPU / query p50 / p95 / p99 ms RSS
    plain pg pg 8.23.1 20,885 6.87x 0.049 ms 0.52 / 0.83 / 1.20 132 MB
    Kysely 0.29.7 10,226 3.36x 0.103 ms 1.06 / 1.89 / 2.70 234 MB
    Knex 3.3.0 9,533 3.14x 0.110 ms 1.15 / 2.05 / 2.80 139 MB
    drizzle-orm 0.45.4 7,257 2.39x 0.145 ms 1.49 / 2.75 / 3.66 140 MB
    TypeORM 0.3.31 6,363 2.09x 0.169 ms 1.66 / 3.21 / 4.40 257 MB
    Sequelize 6.37.8 3,039 1.00x 0.353 ms 3.48 / 6.89 / 8.91 206 MB

    Driver layer

    Same SQL text on every side, no ORM:

    Driver / path Version Queries/s vs pg Client CPU / query p50 / p95 / p99 ms RSS
    postgres.js 3.4.9 18,354 1.26x 0.065 ms 0.59 / 0.92 / 1.42 233 MB
    pg-native 3.9.1 14,986 1.03x 0.068 ms 0.75 / 1.09 / 1.37 134 MB
    pg 8.23.1 14,574 1.00x 0.071 ms 0.75 / 1.18 / 1.56 113 MB
    sequelize.query over pg 7.0.0-alpha.48 14,010 0.96x 0.075 ms 0.78 / 1.25 / 1.76 161 MB
    sequelize.query over pg-native 7.0.0-alpha.48 13,767 0.94x 0.075 ms 0.83 / 1.16 / 1.56 158 MB
    sequelize.query over pg-native 6.37.8 11,043 0.76x 0.093 ms 1.04 / 1.42 / 1.81 148 MB
    sequelize.query over pg 6.37.8 10,474 0.72x 0.099 ms 1.06 / 1.82 / 2.40 149 MB

    @sequelize/core returns timestamptz as a string in raw queries, while pg and v6 return Date. So part of v7's raw-path number comes from not parsing dates.

    pg vs pg-native under each library

    Library over pg q/s over pg-native q/s native gain CPU / query (pg / native) p95 ms (pg / native)
    plain driver 19,670 21,033 +6.9% 0.052 / 0.048 ms 0.94 / 0.83
    Sequelize 5.22.5 3,407 3,379 -0.8% 0.320 / 0.319 ms 5.22 / 5.46
    Sequelize 6.37.8 2,794 2,840 +1.6% 0.385 / 0.378 ms 7.57 / 6.14
    TypeORM 0.3.31 6,231 6,571 +5.5% 0.182 / 0.162 ms 3.43 / 2.66
    Knex 3.3.0 9,631 9,666 +0.4% 0.109 / 0.108 ms 2.10 / 1.88

    TypeORM picks up pg-native by itself if it's installed, so for the "over pg" row we had to hand it a pg module with native hidden.

    Versions

    Library Version Queries/s vs Sequelize 6.37.8 Client CPU / query p50 / p95 / p99 ms RSS
    Sequelize 6.28.0 3,316 1.03x 0.322 ms 3.22 / 6.30 / 7.53 152 MB
    Sequelize 6.32.1 3,303 1.02x 0.324 ms 3.23 / 6.32 / 7.54 152 MB
    Sequelize 6.35.2 3,257 1.01x 0.328 ms 3.28 / 6.40 / 7.69 152 MB
    Sequelize 6.37.7 3,217 1.00x 0.332 ms 3.33 / 6.49 / 7.76 152 MB
    Sequelize 6.37.8 3,228 1.00x 0.331 ms 3.32 / 6.48 / 7.68 153 MB
    @sequelize/core 7.0.0-alpha.43 2,578 0.80x 0.417 ms 4.17 / 8.14 / 9.80 171 MB
    @sequelize/core 7.0.0-alpha.46 2,576 0.80x 0.417 ms 4.19 / 8.15 / 9.77 171 MB
    @sequelize/core 7.0.0-alpha.47 2,586 0.80x 0.417 ms 4.16 / 8.14 / 9.75 170 MB
    @sequelize/core 7.0.0-alpha.48 2,590 0.80x 0.417 ms 4.16 / 8.12 / 9.75 171 MB
    drizzle-orm 0.40.1 8,389 2.60x 0.124 ms 1.30 / 2.27 / 2.83 179 MB
    drizzle-orm 0.44.7 7,787 2.41x 0.134 ms 1.40 / 2.48 / 3.10 179 MB
    drizzle-orm 0.45.4 7,662 2.37x 0.136 ms 1.42 / 2.52 / 3.10 179 MB
    drizzle-orm 1.0.0-rc.4 7,816 2.42x 0.133 ms 1.40 / 2.46 / 3.06 181 MB
    Kysely 0.28.18 10,590 3.28x 0.100 ms 1.04 / 1.71 / 2.34 149 MB
    Kysely 0.29.7 10,558 3.27x 0.100 ms 1.05 / 1.71 / 2.31 152 MB
    Kysely 0.30.0-beta.2 10,632 3.29x 0.099 ms 1.04 / 1.72 / 2.36 150 MB
    MikroORM 6.6.17 902 0.28x 2.026 ms 11.98 / 23.45 / 30.91 183 MB
    MikroORM 7.0.17 1,406 0.44x 0.894 ms 7.62 / 14.92 / 18.88 181 MB
    MikroORM 7.2.5 1,378 0.43x 0.923 ms 7.75 / 15.43 / 19.77 182 MB

    Other databases

    Single node each (official images, on the same machine as everything else). Only the libraries that support the database are listed.

    Library PostgreSQL 17.11 CockroachDB v26.2.8 YugabyteDB 2026.1.2 ClickHouse 26.7.34
    plain driver (pg; ClickHouse: @clickhouse/client 1.24.1) 20,885 q/s · 0.049 ms · p95 0.83 7,744 q/s · 0.112 ms · p95 2.17 6,455 q/s · 0.133 ms · p95 2.40 1,019 q/s · 1.012 ms · p95 16.37
    Sequelize 6.37.8 (CockroachDB: + sequelize-cockroachdb 6.0.6) 3,039 q/s · 0.353 ms · p95 6.89 2,311 q/s · 0.471 ms · p95 8.90 2,186 q/s · 0.498 ms · p95 8.85 n/a
    TypeORM 0.3.31 6,363 q/s · 0.169 ms · p95 3.21 3,938 q/s · 0.276 ms · p95 4.81 3,726 q/s · 0.302 ms · p95 4.95 n/a
    Knex 3.3.0 9,533 q/s · 0.110 ms · p95 2.05 4,809 q/s · 0.213 ms · p95 3.77 4,665 q/s · 0.221 ms · p95 3.51 n/a
    drizzle-orm 0.45.4 7,257 q/s · 0.145 ms · p95 2.75 4,310 q/s · 0.246 ms · p95 4.16 4,127 q/s · 0.256 ms · p95 4.08 n/a
    Kysely 0.29.7 (ClickHouse: + @founderpath/kysely-clickhouse 1.7.0) 10,226 q/s · 0.103 ms · p95 1.89 4,906 q/s · 0.209 ms · p95 3.55 4,708 q/s · 0.221 ms · p95 3.56 768 q/s · 1.418 ms · p95 25.08

    Database server CPU per 1,000 q/s on the plain driver path (sampled from the containers, so rough): PostgreSQL 24, CockroachDB 95, YugabyteDB 124, ClickHouse 743. CockroachDB and YugabyteDB are built to scale out, so a single node isn't their best case. ClickHouse is a columnar engine and isn't meant for point reads like these. We did not test Couchbase: none of the SQL ORMs above support it (Couchbase's own ODM is Ottoman), and with a document model the queries wouldn't be the same work.

    DM8 (Dameng)

    We were also curious about DM8 (it's often described as Oracle-like), so we tried it. It ran from a third-party Docker image with a developer license, on an internal network.

    Library PostgreSQL 17 (pg) DM8 (dmdb 1.0.52452)
    plain driver 19,670 q/s · 0.052 ms · p95 0.94 2,704 q/s · 0.658 ms · p95 11.13
    Sequelize 5.22.5 / sequelize-dm8 5.0.9 (v5 fork) 3,407 q/s · 0.320 ms · p95 5.22 131 q/s · 3.033 ms · p95 73.17
    TypeORM 0.3.31 / + typeorm-dm 1.0.49630 6,231 q/s · 0.182 ms · p95 3.43 1,752 q/s · 0.662 ms · p95 10.51
    Knex 3.3.0 / + knex-dm 1.0.52452 9,631 q/s · 0.109 ms · p95 2.10 2,215 q/s · 0.533 ms · p95 8.86

    The DM8 server itself used less CPU per query than PostgreSQL in this run (~17 vs ~27 per 1,000 q/s). Most of the gap is in the Node driver: dmdb used about 13x the client CPU per query of pg. sequelize-dm8 is a third-party fork of Sequelize v5, so this part isn't on you. With current dmdb it fails as soon as there's more than one connection: it creates a dmdb pool per connection, and dmdb now names every pool 'default' ([20006]). We worked around it to measure it. It also puts the values straight into the SQL text, which may be why the server CPU per query was so high for it (we haven't verified that).

    If any of this is useful for the v7 work and you'd like the raw numbers or the scripts, just say.

  8. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    A small follow-up: in the earlier comments we only measured TypeORM 0.3.31. We used that version because the DM8 dialect (typeorm-dm) needs typeorm@^0.3.20, and then we kept it for the other databases too. We missed testing the current release, TypeORM 1.1.2 (Oct 8). So here are 0.3.25 through 1.1.2 on the same setup, plus one ranking of everything we measured.

    TypeORM versions

    Same four queries and data as before, one run, 3 rounds, sides interleaved. This run was noisier than the earlier ones: rounds varied by up to ±7% instead of ±3%. Our guess is the CockroachDB and YugabyteDB containers sitting next to it. So only differences where the rounds don't overlap count. Rows marked pg-native have pg-native installed, which TypeORM picks up by itself.

    Side Rounds (q/s) Median q/s vs TypeORM 0.3.31 Client CPU / query p50 / p95 / p99 ms RSS
    TypeORM 0.3.25 (2025-06) 6,122 / 6,266 / 6,161 6,161 0.96x 0.184 ms 1.68 / 3.53 / 5.28 255 MB
    TypeORM 0.3.31 (2026-07) 6,428 / 6,486 / 6,411 6,428 1.00x 0.167 ms 1.66 / 3.16 / 4.34 256 MB
    TypeORM 1.0.0 (2026-05) 5,639 / 6,250 / 6,330 6,250 0.97x 0.173 ms 1.69 / 3.28 / 4.66 251 MB
    TypeORM 1.1.0 (2026-07) 5,443 / 5,911 / 5,624 5,624 0.87x 0.192 ms 1.84 / 3.84 / 5.86 251 MB
    TypeORM 1.1.2 (2026-10, latest) 5,691 / 5,802 / 5,871 5,802 0.90x 0.190 ms 1.80 / 3.75 / 5.50 251 MB
    TypeORM 0.3.31 over pg-native 6,560 / 6,609 / 6,950 6,609 1.03x 0.162 ms 1.67 / 2.67 / 3.97 255 MB
    TypeORM 1.1.2 over pg-native 6,416 / 6,186 / 6,394 6,394 0.99x 0.168 ms 1.77 / 2.76 / 4.14 248 MB
    Sequelize 6.37.8 (reference) 2,899 / 3,105 / 2,718 2,899 0.45x 0.373 ms 3.59 / 7.32 / 10.12 207 MB
    plain pg (reference) 20,799 / 18,965 / 21,922 20,799 3.24x 0.050 ms 0.52 / 0.85 / 1.24 132 MB

    On pg, 1.1.2 is about 10% slower than 0.3.31 (5,691–5,871 vs 6,411–6,486 across the rounds, so the ranges don't overlap). 1.0.0 is a little below 0.3.31 (about 3%), and the bigger drop comes with 1.1.0. With pg-native the gap mostly goes away (6,394 vs 6,609).

    Same two versions on single-node CockroachDB and YugabyteDB:

    Side Rounds (q/s) Median q/s vs TypeORM 0.3.31 on the same database Client CPU / query p50 / p95 / p99 ms RSS
    CockroachDB: TypeORM 0.3.31 4,002 / 3,622 / 4,136 4,002 1.00x 0.271 ms 2.74 / 4.81 / 7.15 206 MB
    CockroachDB: TypeORM 1.1.2 3,710 / 3,575 / 4,010 3,710 0.93x 0.293 ms 2.89 / 5.49 / 8.24 205 MB
    YugabyteDB: TypeORM 0.3.31 3,347 / 3,342 / 3,920 3,347 1.00x 0.337 ms 3.01 / 5.82 / 9.13 252 MB
    YugabyteDB: TypeORM 1.1.2 3,462 / 3,777 / 4,034 3,777 1.13x 0.298 ms 2.81 / 4.89 / 7.06 248 MB

    Here the rounds overlap on both databases, so we wouldn't read anything into these.

    Everything in one ranking

    Fastest to slowest, PostgreSQL 17, latest version of each library. The libraries were measured in different runs, so the rank uses each library's ratio to Sequelize 6.37.8 measured in the same run (every run had Sequelize in it). The absolute q/s is shown next to it. Latency is the average of the four queries.

    # Library Version Kind vs Sequelize 6.37.8 (same run) Queries/s Client CPU / query p95 / p99 ms Run
    1 postgres.js 3.4.9 driver + SQL templates 6.71x 20,440 0.063 ms 0.86 / 2.36 run A
    2 pg-promise 12.7.1 SQL library 4.75x 14,456 0.072 ms 1.26 / 1.67 run A
    3 @databases/pg 6.1.0 SQL library 4.35x 13,239 0.079 ms 1.36 / 1.88 run A
    4 Kysely 0.29.7 query builder 3.37x 10,250 0.103 ms 1.82 / 2.46 run A
    5 Slonik 49.11.0 SQL library 3.36x 10,221 0.102 ms 1.64 / 2.21 run A
    6 Knex 3.3.0 query builder 3.14x 9,533 0.110 ms 2.05 / 2.80 run B
    7 drizzle-orm 0.45.4 ORM / query builder 2.46x 7,493 0.139 ms 2.63 / 3.29 run A
    8 Orchid ORM 1.78.27 ORM 2.22x 6,776 0.157 ms 2.83 / 4.01 run A
    9 Zapatos 6.6.1 SQL helpers 2.04x 6,203 0.159 ms 2.96 / 3.70 run A
    10 TypeORM 1.1.2 ORM 2.00x 5,802 0.190 ms 3.75 / 5.50 run C
    11 Sequelize (previous major) 5.22.5 ORM 1.22x 3,407 0.320 ms 5.22 / 7.92 run E
    12 Prisma (adapter-pg) 7.10.1 ORM 1.14x 3,461 0.341 ms 5.60 / 7.48 run A
    13 Objection.js 4.2.0 ORM 1.13x 3,448 0.316 ms 6.01 / 7.58 run A
    14 Sequelize 6.37.8 ORM 1.00x 3,046 0.351 ms 6.86 / 8.35 run A
    15 @sequelize/core 7.0.0-alpha.48 ORM 0.80x 2,590 0.417 ms 8.12 / 9.75 run D
    16 MikroORM 7.2.5 ORM 0.42x 1,292 0.981 ms 16.30 / 21.88 run A

    Ceiling, same run as A: plain pg selecting only the ids, 22,298 q/s (7.32x), 0.046 ms CPU / query.

    Runs:

    • A is the ORM/library run from the previous comment;
    • B is the run with TypeORM and Knex on PostgreSQL;
    • C is this TypeORM run;
    • D is the version run (v6/v7);
    • E is the pg / pg-native run.

    TypeORM 1.1.2 is ranked from run C, which was the noisier one.

  9. SippieCup commented on Oct 19, 2026

    @SippieCup
    Contributor

    Sequelize 6 is basically EoL, we won't be adding performance patches to it, so comparing sequelize versions that arent 7 to other stuff is kinda pointless.

    That said, we should be closer to the other ORMs with your findings on 7.

    Sequelize 7 is in 'alpha' only because we don't have the CLI done yet, and there might be a couple API definitions that we want to change which are breaking for people using it. Thus, we have kept it in alpha until we can get to it as the API definition changes could mean rewriting a whole bunch of queries across an application using it.

    Those API changes though.. I doubt will happen, and even if they are. a well crafted prompt and codegen schematic would be able to fix it for users now. So I think we will be moving it out of alpha soon. Once Generated columns are in for sure.

    That said, I have been using it in production for several years now. and there absolutely no reason not to if you are doing active development. We just did not want to have users building on somehting that would then be stuck out of date and require rewrites etc.

    I will say we use sequelize very differently, while I obviously do have a lot of quick queries like yours, I also work on a lot of big data with deeply nested models where hydration takes up most of the time, so I haven't refined the query builder as much as it could be refined, as it was still a small percentage of the overall work being performed with my tests.

    Regarding your posts:

    One SQL difference we noticed: for query 1, v7 wraps the user in a subquery with ORDER BY "User"."id" LIMIT 1 before joining the roles. v6 does a flat join. It returns the same rows and doesn't seem to matter for the DB here, but it's different.

    this is intentional to fix an issue within older versions of sequelize when setting limits on parent/nested models. Before if you were to set like limit 10, it would limit the total number of rows. If all 10 of those rows were all the same parent row, User in your case, and the first User had 100 messages in a subquery, it would return the first user with 10 messages. not 10 Users with all thier messages.

    subquery: false in the query will make it work the same way without subqueries, but doing ti as subqueries is more efficent.

    the module loader showing up on the hot path,

    Nice catch. If you have a PR for v7 already, I can merge that.

    and more lodash work.

    we should keep working on removing that too..

    This is a big improvement in v7, it's very close to the driver now.

    I would love you to submit these patches as PRs for us so I can merge them now with your attribution. These are definitely oversights that I missed, and had me scratching my head as to how it was so much slower.. thanks for catching it. I will merge asap.

    While reading, I was betting the slowness in query generation was the over-reliance on regex and validation for the query building, rather than doing it correctly by construction. Ideally, there would be very little regex in query generation, rather than being the primary driver This is a legacy thing that has just not been addressed yet. But it shouldnt be that bad as your benchmarks show. Your fixes to the hotpath are greatly appreciated.

    One thing though: v7 gives back timestamptz columns as strings in raw queries ("2026-10-19 08:20:00.03+00"), while pg and v6 give Date objects. So some of this comes from not parsing dates. We guess that's on purpose, just mentioning it.

    This is because we have added temporal api, and soon luxon, support to the alpha. which means not having it return Date objects as default. Date() just has a bunch of issues as im sure you are aware of, that said if you type your model to be Date within the model definition it will return a date object for you. This is just you likely having a legacy model definition.

    Experiments that change behavior (cost only, not proposals)
    v6 run() creates new Error() for every query (dialects/postgres/query.js, to keep the call-site stack for DB errors). Without it: +7.0% (+5.8% to +8.2%). That stack is useful, so this is just to show what it costs. Capturing it lazily isn't possible, but maybe it could be opt-out.

    I think this might be useful to have an opt-out configuration on a per-query or globally. @WikiRik I would like your opinion onn the matter. The issue becomes when these issues happen in production, you really have no idea why. That said, angular does a similar thing with production mode.

    options = cloneDeep(options) in findAll / findOne / count / … (both versions, 10 places in model.js). A shallow copy instead: +3.2% in both v6 and v7. This isn't safe as it is, because the caller's include objects would get mutated. It just shows the defensive copy isn't where most of the time goes.

    This we cant do. we intentionally deep clone to protect against contamination between shared callers when working on hooks and nested models.
    For example: through models runs defaultsLodash(include.through, {...}) and then ANDs through.scope into through.where.

    With a shallow copy, that writes into the caller's object. Each reuse adds the scope one more time, so the SQL grows on every call. It also stores a parent pointer back. A module-level const INCLUDE = [...] is very common, which would mean that those hooks would not get overwritten by that query's particular changes. This happens with like.. timestamps and paranoid hooks at a global level.

    The better solution is to just make a better clonedeep function, that suits our particular usage. rather than shallow copy.

    With both changes alpha.48 lands right where v6 is (3,161 vs 3,189). The isModelStatic one looks safe to us. We'd be glad to send a PR for it if you want.

    the constructor fix and rio are probably good to merge. if you open PRs.

    isModelStatic actually has an open PR that should be able to do it here: #18234 So i'll just review that tonight and see if there is anything more needed. I thought that was actually part of the rollup when 48 shipped which is why i was confused.

    For RIO. you can probably speed it up a bit more, if you look at quoteTable(), it gets used and loops through every option. but we only actually use indexHints and tableHints in it. so we can loop through those instead, and then get the values from a direct assignment instead of going though the massive for loop.

    const receivedOptionNames: string[] = [];
    for (const name of allSupportableOptions) {
        const value = (receivedOptions as Record<string, unknown>)[name];
        // It is _essential_ that boolean options are false by default!
        if (value !== undefined && value !== false) receivedOptionNames.push(name);
    }
    

    that'll speed it up a crap ton more.

    If you open the two PRs for the constructor and RIO, I would appreicate it :)

    Also If you share your benchmarking with me. I can continue to iterate and bring it down. That said, the 3 things you pointed out should give like a 30% improvement from the current baseline.

  10. WikiRik commented on Oct 19, 2026

    @WikiRik
    Member

    I haven't actively looked at performance improvements yet, I think we can ship some before v7 comes out but I don't think we should focus on it.
    For the new Error() specifically; I think we can look into a per-query opt-out for the queries that people know they don't need the error stack on. Adding an opt-out globally sounds too risky to me atm, but if there's real demand for it we can always add it later

  11. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    Thanks a lot for the detailed replies, that clears up a lot. @SippieCup @WikiRik

    A correction to my earlier comment first: I said lodash omit deep-clones there. It doesn't. With a single top-level key it makes a shallow copy. The cost comes from collecting every key with getAllKeysIn (own and inherited, plus symbols) and then baseUnset, once per instance. So the rest copy (const { comesFromDatabase, ...rest } = options) should be equivalent for plain option objects, not just "probably fine".

    I opened the two PRs you asked for:

    Measured against a build of current main (d191d5b), not the alpha.48 release, since main is quite a bit ahead: the constructor change is 1.09x, the loop 1.06x, and both together 1.16x on the same four queries. Details are in the PRs.

    @WikiRik understood that performance isn't the focus before v7, so these are meant as small, low-risk changes. A per-query opt-out for the new Error() would work for us. We'd only use it on a few hot read paths anyway, so a global switch isn't something we need.

    On #18234, one more data point that might help it along. When I ran the benchmark directly on a Windows host instead of in a Linux container, stock alpha.48 dropped to ~400 q/s (v6: ~2,100 on the same machine). With only isModelStatic cached it went back to ~2,000 q/s. On Linux that fix was +11–15%, but on Windows the per-call require() seems to go to the file system each time, so it's closer to 5x. Anyone developing on Windows probably sees v7 as a lot slower than it really is.

    The benchmark is here: https://github.com/ramazansancar/sequelize-orm-bench. It has the same four queries on synthetic data (seed script included), and v6 and v7 share one model file. Everything runs in Docker, one compose file per comparison, and compose.builds.yml runs local builds (packed .tgz files) next to each other, which is how the PR numbers were made. If you want other query shapes in it, let me know and I'll add them.

    The rest makes sense to us. On the dates, our case was raw sequelize.query() with no model, so strings there are expected. Thanks for the subQuery: false tip too. And agreed on cloneDeep: a clone that only walks the parts it needs (include trees, where objects) sounds like the right way to go. I can look into that later if it helps.

  12. ramazansancar commented on Oct 19, 2026

    @ramazansancar
    ContributorAuthor

    Full numbers from the benchmark repo for #18556 and #18557, in case they're useful here too.

    Setup: Node 24.22.0 and PostgreSQL 17 in Docker (compose.builds.yml), synthetic data (21k users, 500k messages). Four read queries mixed 35/25/25/15, 12 in flight, 20 s per run, 5 interleaved rounds, median. Every build was packed from its branch, and all four returned the same results (same fingerprint), 0 errors.

    build rounds (q/s) median q/s vs main client CPU / query
    main (d191d5b) 2300 / 2459 / 2315 / 2372 / 2453 2372 1.00x 0.462 ms
    #18556 (constructor) 2663 / 2636 / 2560 / 2585 / 2579 2585 1.09x 0.422 ms
    #18557 (rejectInvalidOptions) 2528 / 2551 / 2518 / 2484 / 2521 2521 1.06x 0.431 ms
    both 2811 / 2735 / 2764 / 2728 / 2751 2751 1.16x 0.395 ms

    Latency per query, p50 / p95 / p99 in ms:

    build Q1 findByPk + M:N include Q2 findAll + hasMany include Q3 findAll Q4 count
    main 4.50 / 8.91 / 11.24 4.85 / 9.63 / 12.10 4.37 / 8.73 / 11.20 4.31 / 8.59 / 11.09
    #18556 4.12 / 8.24 / 10.38 4.37 / 8.63 / 10.29 3.98 / 7.80 / 9.85 3.93 / 7.85 / 9.72
    #18557 4.27 / 8.40 / 10.33 4.62 / 8.95 / 10.83 4.15 / 8.07 / 9.98 4.06 / 8.04 / 10.04
    both 3.88 / 7.72 / 9.65 4.15 / 8.12 / 10.19 3.74 / 7.43 / 9.40 3.72 / 7.40 / 9.54

    With 12 queries in flight the process is CPU-bound, so the latency drop follows the CPU per query. Memory stays the same (226-230 MB RSS).

    To reproduce: put the packed core, postgres and utils tarballs of each branch in builds/<name>/ and run docker compose -f compose.builds.yml run --rm bench.

  13. ramazansancar commented on Oct 22, 2026

    @ramazansancar
    ContributorAuthor

    I’m going to spend some more time on the improvements here. So, even though two PRs are already included, it looks like I might open a few additional ones. I’ll post an update here in a couple of weeks.

    PRs: https://github.com/sequelize/sequelize/pulls?q=is%3Apr+state%3Aclosed+author%3Aramazansancar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-approval

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions