Skip to content

Share the repo mapping entries recorded by loaded .bzl files - #32977

Draft
fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:bzl-recorded-repo-mappings-nested-set
Draft

fmeum wants to merge 1 commit into
bazelbuild:masterfrom
fmeum:bzl-recorded-repo-mappings-nested-set

Conversation

@fmeum

@fmeum fmeum commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Every BzlLoadValue copied the repo mapping entries recorded by the .bzl files it loads into an ImmutableTable of its own, so that each value retained the entries of its entire load closure.

Store the entries as a NestedSet that shares the sets of the loaded files. SimpleRepoMappingRecorder keeps the sets of the loaded files instead of copying their entries, and the table of all entries is only computed where it is used: for the .bzl files of module extensions and for repository rules.

Motivation

In a heap dump taken after analysis of a large repo with 22k .bzl files, most of them generated by rules_js for npm packages, these tables took 58 MB (8.7% of the heap). 75% of them consisted of the same 21 entries of the load closure of the rules_js .bzl files plus a single entry of their own, so they can't be deduplicated by interning, but they share almost everything. With this change, the memory retained exclusively by BzlLoadValues in that heap dropped from 59.0 MB to 5.8 MB.

Build API Changes

No

Release Notes

RELNOTES: None

Every BzlLoadValue copied the repo mapping entries recorded by the .bzl
files it loads into a table of its own, so that each value retained the
entries of its entire load closure.

Store the entries as a NestedSet that shares the sets of the loaded
files. The table of all entries is only computed where it is used, for
the .bzl files of module extensions and for repository rules.

This branch has not been deployed

No deployments
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