hundreds-father-404
05/15/2019, 8:46 PMwitty-crayon-22786
05/15/2019, 8:46 PMwitty-crayon-22786
05/15/2019, 8:46 PMhundreds-father-404
05/15/2019, 8:48 PMsize
is the average size of a memory block, and count is the # of blocks allocated
Should the memory block for the native.py
handles you just referenced continue to substantially grow both in size and in count throughout the rule, or should any memory be freed up along the way?witty-crayon-22786
05/15/2019, 8:50 PMwitty-crayon-22786
05/15/2019, 8:51 PMwitty-crayon-22786
05/15/2019, 8:51 PM--enable-pantsd
, and look at the memory usage of the process after running thingshundreds-father-404
05/15/2019, 8:52 PMwitty-crayon-22786
05/15/2019, 8:53 PMwitty-crayon-22786
05/15/2019, 8:53 PMwitty-crayon-22786
05/15/2019, 8:53 PMwitty-crayon-22786
05/15/2019, 8:53 PMwitty-crayon-22786
05/15/2019, 8:54 PM@rules
won't persist past the end of the runwitty-crayon-22786
05/15/2019, 8:54 PM--enable-pantsd
, you'll see that this persists.hundreds-father-404
05/15/2019, 8:58 PMthings created in the bodies ofAgreed. I think the issue is that the rule body takes too much memory.won’t persist past the end of the run@rules
test
is using 2.42 more megabytes than list
during the rule just for the memory allocated with `native.py`’s to_value()
witty-crayon-22786
05/15/2019, 8:59 PMwitty-crayon-22786
05/15/2019, 8:59 PMwitty-crayon-22786
05/15/2019, 9:00 PMwitty-crayon-22786
05/15/2019, 9:00 PMhandles
map.hundreds-father-404
05/15/2019, 9:01 PM__repr__
being in the outputted graph but I didn’t understand how you got to that insightwitty-crayon-22786
05/15/2019, 9:02 PM--native-engine-visualize-to
for what should have been a relatively small graph, i could see in py-spy that it was spending a crazy amount of time in __repr__
(minutes)witty-crayon-22786
05/15/2019, 9:03 PMrepr
of everything that it holds (and in a stable state, should be ~equal to the content of the _handles
map)witty-crayon-22786
05/15/2019, 9:04 PMwitty-crayon-22786
05/15/2019, 9:05 PMobjgraph
... possible that running an objgraph
analysis on the handles map to find "large" things would work.witty-crayon-22786
05/15/2019, 9:07 PMobjgraph.show_most_common_types(objects=self._handles)
...?witty-crayon-22786
05/15/2019, 9:08 PMwitty-crayon-22786
05/15/2019, 9:08 PMhundreds-father-404
05/16/2019, 12:36 AMrun_python_test()
into multiple helper functions / rules, the memory usage would decrease because run_python_test()
would have less variables in its scope that it has to keep in scope throughout the lifetime of the function. Maybe I’ve been reading too much about how Rust works and this doesn’t apply in Python, but was thinking along the lines of a function keeps its local variables on the stack then drops them after
If this were true, then I would expect the new inject_init()
rule to result in the memory usage increasing less than before between the init setup and what comes right before. But, it actually slightly increases from before.
I’m a bit at a loss on this memory investigation. Going to take a break and come back in an hour or so. Will reread everything you suggestedwitty-crayon-22786
05/16/2019, 12:45 AMself._handles
, one way or the otherwitty-crayon-22786
05/16/2019, 12:46 AMwitty-crayon-22786
05/16/2019, 12:47 AMobjgraph
should show that)hundreds-father-404
05/16/2019, 12:48 AMwould look at the content ofIt’s all just, one way or the otherself._handles
CDataOwnGC
, which wasn’t super helpful. I then had the idea to print the obj
before it gets converted from CFFI into a handle
. Wasn’t very helpful, but now I’m thinking to instead use sys.getsizeof( obj)
, which can show us what’s so huge.hundreds-father-404
05/16/2019, 1:03 AMto_value()
that’s larger than 100 bytes: https://gist.github.com/Eric-Arellano/cf886685f990eb5520c1a1d97a56dcc6#file-size-of-objects-send
Is this expected? We are materializing more now that we resolve all transitive depswitty-crayon-22786
05/16/2019, 1:04 AMwitty-crayon-22786
05/16/2019, 1:04 AMwitty-crayon-22786
05/16/2019, 1:06 AMwitty-crayon-22786
05/16/2019, 1:07 AMwitty-crayon-22786
05/16/2019, 1:08 AMwitty-crayon-22786
05/16/2019, 1:08 AMwitty-crayon-22786
05/16/2019, 1:09 AMcontext.from_value
does the opposite of to_value
hundreds-father-404
05/16/2019, 1:20 AMfrom_value
that’s > 200
bytes: https://gist.github.com/Eric-Arellano/cf886685f990eb5520c1a1d97a56dcc6#file-size-of-objects-received
That’s a whole lot of datatypes
being passed around. And not sure why we ever materialize files in either directionwitty-crayon-22786
05/16/2019, 1:21 AMhundreds-father-404
05/16/2019, 1:21 AM__init__.py
rule does make a difference, but I think primarily because it uses Daniel’s new builtin rule to go from Digest -> Snapshot
so we avoid Digest -> FIlesContent
witty-crayon-22786
05/16/2019, 1:21 AMobjgraph.show_most_common_types(objects=[self.from_value(h) for h in self._handles])
witty-crayon-22786
05/16/2019, 1:21 AMwitty-crayon-22786
05/16/2019, 1:22 AMhundreds-father-404
05/16/2019, 1:23 AMnative.py
when it’s over and you should inspect self._handles
? Maybe put it in raise_or_return(self, pyresult)
, as I think that gets called near the endwitty-crayon-22786
05/16/2019, 1:26 AMwitty-crayon-22786
05/16/2019, 1:27 AMwitty-crayon-22786
05/16/2019, 1:27 AMhundreds-father-404
05/16/2019, 2:16 AMCDataOwn 985
str 60
function 50
partial 9
tuple 6
NoneType 5
ABCMeta 5
generator 4
Digest 3
int 3
None
After `./pants --no-v1 --v2 test tests/python/pants_test/util:strutil`:
CDataOwn 1320
str 182
function 50
int 40
tuple 38
Digest 34
NoneType 32
generator 28
bytes 9
Snapshot 9
None
witty-crayon-22786
05/16/2019, 2:20 AMfrom_value
...?witty-crayon-22786
05/16/2019, 2:21 AMhundreds-father-404
05/16/2019, 2:21 AMCDataOwnGC
This is the snippet I added to `run_console_rules()`:
from pants.engine.native import Native
import objgraph
native_context = Native().context print(objgraph.show_most_common_types(objects=[native_context.from_value(h) for h in native_context._handles]))
witty-crayon-22786
05/16/2019, 2:22 AMwitty-crayon-22786
05/16/2019, 2:23 AMtype(from_value(...))
should ~always match one of the Params or return values of a @rulewitty-crayon-22786
05/16/2019, 2:24 AMhundreds-father-404
05/16/2019, 2:25 AMExternContext._handles
after the run: https://gist.github.com/Eric-Arellano/cf886685f990eb5520c1a1d97a56dcc6#file-leftover-in-handles
The file content looks to be the culprit to me again. I ran the same on ./pants list
and found that it too has materialized file content, but the key difference is that it’s O(1)
for space. For ./pants test
, it’s O(n)
where n is # of source files in the closurewitty-crayon-22786
05/16/2019, 2:27 AMwitty-crayon-22786
05/16/2019, 2:29 AM