Skip to content

perf (evaluate): EPUB assembly does a per-page Buffer→string→Buffer round trip and emits 3 tiny zip chunks per entry #25

Description

@JavaGT

Filed by the Account-2 read-only amplifier (2026-09-16, HEAD f635e62). Problem (CPU hot path, coordinator-verified):

  • Pages double-convert: pageBodyOf returns d.toString('utf8') (src/epub.mjs:251-255), wrapPage composes strings (src/epub.mjs:296-299 thunk), then resolveData re-encodes with Buffer.from(d,'utf8') when the payload isn't already a Buffer (src/epub.mjs:33-37) before deflate — one full decode+re-encode per page per assembly.
  • zipChunks yields 3 chunks per entry — 30-byte local header, name, payload (src/epub.mjs:154-158) — so a book pushes hundreds of micro-writes through the pipeline; header+name could share one combined alloc.
  • zipChunks also re-implements layout()'s offset/dirSize accounting inline (src/epub.mjs:151-153 vs :49-58) — mirrored accounting, drift currently mitigated only by the byte-identity test (test/epub-integrity.test.mjs:131).

Evaluation question (implementation is NOT the todo until measured): buffer-concat wrapping + combined header/name alloc, measured in the bench zip_assembly section — the one harness that exists for this path. Byte-identity tests must stay green. Note: zip_assembly outputBytesAgree:false vs perf/baseline is expected from the intentional rewrite — compare current-vs-candidate, not vs baseline. Deflate level should get a pin regardless (tracked under #19).

Proposed focus packet: wrapPage on Buffers (viewport insert as buffer concat), single header+name alloc in zipChunks, shared accounting helper, bench A/B + epub-integrity green.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions