Add note about ctx.files memory impact#28753
Open
hauserx wants to merge 1 commit intobazelbuild:masterfrom
Open
Add note about ctx.files memory impact#28753hauserx wants to merge 1 commit intobazelbuild:masterfrom
hauserx wants to merge 1 commit intobazelbuild:masterfrom
Conversation
Collaborator
|
The ideal solution would be to migrate these to return special lists that only flatten the depset when needed. I don't know whether that's feasible though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Usage of
ctx.filesin rules can be memory heavy in case of a lot of inputs. According to current documentation usingctx.filesis shortcut forand indeed when creating some syntetic benchmarks noticed high memory usage that could be explained by file depset being eagerly resolved.
I have updated documentation with info about it and small sample of creating depset from
ctx.attras an alternative.I have also found in Kleaf documentation note that also recommends using depsets in all cases but when small number of inputs is guaranteed: https://android.googlesource.com/kernel/build/+/refs/heads/main/kleaf/docs/kleaf_development.md#prefer-depset-over-in-rules
Motivation
When investigating high memory usage for some of our heavy builds (~1M actions) noticed high memory usage in loading/analysis phase on pretty basic synthetic benchmarks. Benchmark is basically 100k-1M small actions, each using the same 1k-10k-100k files. Manipulating number of actions and number of input files shows that around 8 bytes is needed per each occurrence of an input file. So e.g. for 100k actions each using same 10k input files, bazel reports
used-heap-size-after-gc:around 8GB after the analysis phase (bazel build --nobuild //...) . Taking heap dumps showed that ~95% of memory is consumed byNestedSets. Using solution described in this PR reduced memory to ~400MB.Build API Changes
No
Release Notes
RELNOTES: None