Skip to content

LZMA: Update SDK to 26.03 - #36

Open
poiru wants to merge 1 commit into
nsis-dev:masterfrom
poiru:lzma
Open

poiru wants to merge 1 commit into
nsis-dev:masterfrom
poiru:lzma

Conversation

@poiru

@poiru poiru commented Sep 16, 2026

Copy link
Copy Markdown

Updates NSIS from its legacy 2006 LZMA implementation to LZMA SDK 26.03.

The old C++ encoder and custom decoder have been replaced with the current 7-Zip C encoder and decoder. Thin adapters preserve NSIS’s existing compressor and installer-stub interfaces.

Motivation

The legacy decoder advanced its dictionary position using a runtime integer modulo for every decompressed byte:

dictionaryPos = (dictionaryPos + 1) % dictionarySize;

Because dictionarySize is determined at runtime, this can produce an integer division in the inner decompression loop. Large payloads can therefore incur millions of divisions.

The current 7-Zip decoder increments the dictionary position, wraps only at buffer boundaries, and copies matches in runs. This should substantially reduce CPU time during extraction.

Changes

  • Vendor the required LZMA SDK 26.03 C sources.
  • Replace the legacy C++ encoder with LzmaEnc.
  • Replace the custom decoder with LzmaDec.
  • Add streaming adapters for NSIS’s existing compressor and decompressor interfaces.
  • Preserve the five-byte LZMA properties header and end marker.
  • Preserve incremental input and output behavior.
  • Preserve NSIS’s existing compression worker thread.
  • Keep the SDK encoder single-threaded within that worker thread.
  • Reuse decoder allocations across stream resets.
  • Update compiler, installer-stub, and test build definitions.
  • Remove the obsolete SDK sources and historical sdk.diff.
  • Retain the original NSIS license headers and comments unchanged.

Compatibility

The generated stream format remains unchanged:

  1. Five-byte LZMA properties header.
  2. Raw LZMA payload.
  3. LZMA end marker.

Existing NSIS streaming semantics are also retained, including partial input consumption, bounded output buffers, reset behavior, and the existing result codes.

Replace the legacy 2006 LZMA encoder and custom decoder with the current
7-Zip LZMA SDK C implementation.

Adapt the existing NSIS streaming interfaces to LzmaEnc and LzmaDec,
preserving the five-byte properties header, end marker, allocator
behavior, and single-worker-thread compression model.

The modern decoder eliminates the integer modulo performed for every
decompressed byte and copies matches in runs, substantially improving
extraction performance for large LZMA-compressed payloads.
@poiru

poiru commented Sep 16, 2026

Copy link
Copy Markdown
Author

@sredna We were experimenting with replacing NSIS and noticed that our custom installer extracted the payload way faster. Codex identified this performance problem and performed the SDK upgrade. Mind allowing the CI run?

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

Successfully merging this pull request may close these issues.

1 participant