Skip to content

Proposal: fast path for assert.deepEqual with typed arrays #4294

Description

@LinusU

assert.deepEqual is very slow when given large typed arrays. This is however easily worked around by wrapping them in buffers instead. It would be awesome if Node.js could use the same performant code to compare Typed Arrays as it uses for buffers.

This is my current local workaround:

function assertTypedArrayEquals (actual, expected, message) {
  const actualBuffer = new Buffer(actual)
  const expectedBuffer = new Buffer(expected)

  if (actualBuffer.equals(expectedBuffer)) return

  throw new assert.AssertionError({
    message: message,
    actual: actual,
    expected: expected,
    operator: 'deepEqual',
    stackStartFunction: assertTypedArrayEquals
  })
}

This brings the test down to a few milliseconds from over one second.

Activity

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

    assertIssues and PRs related to the assert subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions