Skip to content

perf: compress embedded JDK constructor bundle and trim internal omap for v0.8.1 - #33

Merged
VillanCh merged 1 commit into
mainfrom
perf/compact-jdk-constructor-code
Nov 20, 2026
Merged

VillanCh merged 1 commit into
mainfrom
perf/compact-jdk-constructor-code

Conversation

@VillanCh

Copy link
Copy Markdown
Contributor

Summary

Two binary-size optimizations targeting consumers embedding github.com/yaklang/javajive (including yak full & slim builds):

  1. Deterministic chunked-Zstd JDK constructor bundle (-9.40 MiB embedded data)

    • Keep the reviewed classparser/jdk_constructor_code.zip (17,909,526 B / 17.08 MiB) on disk as the source of truth (matching perf: compress embedded JDK metadata for v0.8.0 #32's pattern for jdk_metadata_catalog.json).
    • Extend tools/compressjdk with -constructor-zip (wired into go generate ./classparser) to pack all 9,816 JDK 8/9/11/16/17/21 classfiles sorted by (className, release) into 1 MiB chunks compressed with deterministic Zstd (SpeedBestCompression, concurrency 1, CRC enabled) into classparser/jdk_constructor_code.bundle.zst (8,048,188 B / 7.68 MiB, -55.1%).
    • Update classparser/jdk_constructor_code.go to embed only jdk_constructor_code.bundle.zst, lazily decode only the manifest on first JDK candidate lookup, lazily decompress each 1 MiB chunk at most once via per-chunk sync.Once (zero mutex contention), verify per-class SHA-256 on every lookup, and return an owned copy.
    • Add TestJDKCompressedConstructorCodeMatchesSource verifying profile counts and byte-for-byte equality across all 9,816 classes against jdk_constructor_code.zip, and register it in tools/requiredci/main.go.
  2. Trim dead generic methods from internal/omap (-40+ unused methods)

    • Remove ~40 unused exported methods (SearchGlobKey, SearchRegexKey, MarshalJSON, UnmarshalJSON, ValuesMap, WalkMap, OrderInsert, Filter, Flat, Merge, etc.) and dead helper files from the private internal/omap package, keeping only the 10 methods used by javajive.
    • Replace trivial defer o.lock.Unlock() / defer o.lock.RUnlock() with explicit unlocks to avoid generating .deferwrap1 closures per generic shape.
    • Prevents downstream binaries with dynamic reflection (reflect.MethodByName) from retaining ~1,200+ unused generic wrapper functions (~1 MiB).
  3. Bump Version to 0.8.1.

Validation

  • go generate ./classparser produces byte-identical SHA-256 for both jdk_constructor_code.bundle.zst and jdk_metadata_catalog.json.zst.
  • go vet ./classparser ./tools/compressjdk ./tools/requiredci ./internal/omap . passes cleanly.
  • go test -race ./classparser -run '^(TestJDKCompressedConstructorCodeMatchesSource|TestAdversarialPlatformConstructorCodeIdentityAndEffectProof|TestAdversarialPlatformInterfaceDeclarationsUsePinnedOriginalFlags|TestJDKCompressedCatalogMatchesSource)$' passes.
  • go run ./tools/requiredci -check, -run corpus, and -run algorithm all pass.
  • go test ./classparser/decompiler/rewriter/... ./internal/filesys/... ./tools/requiredci/... passes.

@VillanCh
VillanCh merged commit 203188a into main Nov 20, 2026
5 checks passed
@VillanCh
VillanCh deleted the perf/compact-jdk-constructor-code branch November 20, 2026 07:14
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