Skip to content

perf(nodeenv): unpack the node.js zip archive in parallel - #459

Merged
ekalinin merged 2 commits into
masterfrom
feat/parallel-zip-extraction
Oct 31, 2026
Merged

ekalinin merged 2 commits into
masterfrom
feat/parallel-zip-extraction

Conversation

@ekalinin

@ekalinin ekalinin commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

See CONTRIBUTING.md for the rules behind this checklist.

On Windows the node.js zip archive is extracted one file at a time, and
scanners that check every new file make that slow: in #366 the 1971 files
of node-v22.4.1-win-x64.zip take three hours, and three minutes with 100
threads. pre-commit is hit hardest, as it creates an environment per node
hook and runs nodeenv with its own fixed arguments.

The zip branch of download_node_src now extracts the files with 32
threads (extract_workers, a module constant):

  • Every directory is created first in the main thread, from the directory
    entries and the parents of the files. Before Python 3.13 zipfile fails
    when two threads create the same directory.
  • The first file that fails stops the extraction, and the files that have
    not started are dropped. Ctrl+C does the same: the main thread waits with
    a 0.1 s timeout, since before Python 3.14 Ctrl+C does not interrupt
    waiting on a lock on Windows.
  • Each file is still extracted by ZipFile.extract, which sanitizes the
    names. Tar archives are extracted as before.

--no-parallel-extract, or parallel_extract = False in the [nodeenv]
section of ~/.nodeenvrc, turns this off and extracts the zip with the
old extractall, one file at a time. --parallel-extract, the default,
turns it back on over the config. The config also reaches pre-commit.

The real node-v22.4.1-win-x64.zip gives the same 1971 files and 500
directories, with the same hashes, as extractall. CI cannot reproduce a
slow scanner, so the speedup can only be confirmed in the issue.

Fixes #366

  • Tests cover the change
  • tox passes: the tests and flake8
  • CHANGES has an entry under Version [unreleased], if nodeenv's
    behavior changes
  • README.rst is updated, if the change affects what it documents
  • The title has the form type(scope): subject

On Windows, scanners that check every new file made the one by one
extractall of the node.js zip take hours. The zip branch of
download_node_src now extracts the files with 32 threads, after
creating every directory in the main thread: before Python 3.13
zipfile fails when two threads create the same directory.

The first failing file stops the extraction and the files that have
not started are dropped, and so does Ctrl+C. The main thread waits
with a timeout, since before Python 3.14 Ctrl+C does not interrupt
waiting on a lock on Windows. Tar archives are extracted as before.

Fixes #366
--no-parallel-extract, or parallel_extract = False in the [nodeenv]
section of a config file, extracts the node.js zip archive with the old
one by one extractall. --parallel-extract, the default, turns it back
on over the config. The config also reaches pre-commit, which runs
nodeenv with its own arguments. Tar archives are not affected.
@ekalinin
ekalinin merged commit ac28019 into master Oct 31, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support parallel extraction for zip files

1 participant