Skip to content

util.inspect is slow for large sparse arrays #14487

Closed
@not-an-aardvark

Description

@not-an-aardvark
  • Version: 8.2.1
  • Platform: macOS
  • Subsystem: util
  1. Open the REPL
  2. Enter Array(100000000)

After about 15 seconds, [ <100000000 empty items> ] is printed.

In contrast, entering the same thing into the Chrome devtools console results in an output almost immediately.

It looks like this happens because util.inspect iterates from 0 to array.length. It might be better to iterate over Object.keys(array) instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceIssues and PRs related to the performance of Node.js.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions