Skip to content

Stream module lockfiles directly to disk - #30428

Closed
dzbarsky wants to merge 5 commits into
bazelbuild:masterfrom
dzbarsky:codex/stream-module-lockfiles-dzbarsky
Closed

Stream module lockfiles directly to disk#30428
dzbarsky wants to merge 5 commits into
bazelbuild:masterfrom
dzbarsky:codex/stream-module-lockfiles-dzbarsky

Conversation

@dzbarsky

Copy link
Copy Markdown
Contributor

Description

Stream MODULE.bazel.lock serialization through a buffered UTF-8 writer instead of building the complete JSON as a String. The same helper writes both workspace and hidden lockfiles. Preserve the existing trailing newline and I/O failure logging, and add a regression test for the exact persisted JSON and newline.

Motivation

A real hidden lockfile reached 456,397,262 bytes (435.254 MiB). Gson.toJson(updatedLockfile) + "\n" creates two full strings, about 870 MiB of transient heap, and can fail in BazelLockFileModule.updateLockfile with java.lang.OutOfMemoryError: Java heap space.

Streaming Gson directly to disk removes those full-size intermediate strings.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

@google-cla

google-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

A real hidden lockfile reached 456,397,262 bytes (435.254 MiB).
Serializing it as Gson.toJson(updatedLockfile) + "\n" builds two
full strings, adding about 870 MiB of transient heap and causing
java.lang.OutOfMemoryError: Java heap space in updateLockfile.

Stream Gson through a buffered UTF-8 writer instead, while preserving
the trailing newline and the existing I/O failure behavior. Add a
regression test for the exact persisted JSON and newline.

(cherry picked from commit 715f49f)
@dzbarsky
dzbarsky force-pushed the codex/stream-module-lockfiles-dzbarsky branch from 72ee047 to 1cc1957 Compare July 22, 2026 22:41
@dzbarsky
dzbarsky marked this pull request as ready for review July 22, 2026 22:45
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. area-Bzlmod Bzlmod-specific PRs, issues, and feature requests awaiting-review PR is awaiting review from an assigned reviewer labels Jul 22, 2026
@fmeum

fmeum commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

@bazel-io fork 9.3.0

Comment thread src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java Outdated
Comment thread src/main/java/com/google/devtools/build/lib/bazel/bzlmod/BazelLockFileModule.java Outdated
@dzbarsky

Copy link
Copy Markdown
Contributor Author

@fmeum I addressed all four review comments, including preserving an existing IOException cause and wrapping any other JsonIOException in an IOException. All 37 presubmit checks now pass, including Windows ARM64, and every review thread has a response. Could you take another look when you have a chance?

-zbarskybot

@github-actions github-actions Bot added the community-reviewed Reviewed by a trusted community contributor label Jul 23, 2026
@Wyverald Wyverald added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Jul 27, 2026
@github-actions github-actions Bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Bzlmod Bzlmod-specific PRs, issues, and feature requests community-reviewed Reviewed by a trusted community contributor team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants