Commit 9610ae8
Update PythonZipper action to use CommandLineItem.CapturingMapFn
### Summary
This PR attempts to address bazelbuild#14890.
This updates the PythonZipper action to use a `CommandLineItem.CapturingMapFn` to defer expanding arguments until after analysis. I used `CapturingMapFn`, as it seemed like the only way to go about implementing the arg filtering that is done by the current code to exclude the `executable` and `zipFile` artifacts.
### Test Plan
Use the example from bazelbuild#14890 of looking at memory usage in tensorflow before/after this patch is applied on top of version `5.0.0`
Initial Setup
```
git clone [email protected]:tensorflow/tensorflow.git
cd tensorflow
python3 -m venv venv
source venv/bin/activate
pip install numpy
```
View memory usage at 5.0.0:
```bash
# STARTUP_FLAGS from https://bazel.build/rules/performance#enabling-memory-tracking
$ bazel ${STARTUP_FLAGS[@]} build --nobuild //tensorflow/python/...
$ bazel ${STARTUP_FLAGS[@]} dump --rules | egrep '(RULE|py_)'
RULE COUNT ACTIONS BYTES EACH
py_test 1,714 15,390 413,338,632 241,154
py_library 1,102 0 2,097,152 1,903
py_binary 33 198 8,914,840 270,146
py_runtime 6 0 0 0
py_runtime_pair 3 0 0 0
_concat_flatbuffer_py_srcs 2 2 0 0
$ bazel ${STARTUP_FLAGS[@]} info used-heap-size-after-gc
635MB
```
View memory usage at 5.0.0 with this patch applied:
```bash
$ ~/code/bazel/bazel-bin/src/bazel ${STARTUP_FLAGS[@]} dump --rules | egrep '(RULE|py_)'
RULE COUNT ACTIONS BYTES EACH
py_test 1,714 15,390 65,323,312 38,111
py_library 1,102 0 2,359,576 2,141
py_binary 33 198 524,400 15,890
py_runtime 6 0 0 0
py_runtime_pair 3 0 0 0
_concat_flatbuffer_py_srcs 2 2 0 0
$ ~/code/bazel/bazel-bin/src/bazel ${STARTUP_FLAGS[@]} info used-heap-size-after-gc
283MB
```
Ensure that the generated actions have not changed:
```bash
$ bazel aquery --build_python_zip 'mnemonic("PythonZipper", //tensorflow/python/...)' > /tmp/bazel_5_out
$ ~/code/bazel/bazel-bin/src/bazel aquery --build_python_zip 'mnemonic("PythonZipper", //tensorflow/python/...)' > /tmp/bazel_5_patched_out
$ diff /tmp/bazel_5_out /tmp/bazel_5_patched_out
# note: no diff output
```
Closes bazelbuild#15037.
PiperOrigin-RevId: 4412576951 parent 6464f1c commit 9610ae8
File tree
2 files changed
+18
-4
lines changed- src/main/java/com/google/devtools/build/lib/bazel/rules/python
2 files changed
+18
-4
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
Lines changed: 17 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
367 | 368 | | |
368 | 369 | | |
369 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
370 | 387 | | |
371 | 388 | | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | 389 | | |
377 | 390 | | |
378 | 391 | | |
| |||
0 commit comments