Reduce memory usage of tests#1606
Conversation
This is awesome!
Which means this should probably be labeled wip and/or renamed with
Doesn't look like it 😞 >>> memoryview.mro()
[memoryview, object]I guess a custom bytes type we make in |
c596554 to
60035b4
Compare
- eth/vm/memory.py:Memory.read() used to return a bytes() initialized with the requested memory, this created an often unnecessary copy of the data. It now returns a memoryview(), which is a python wrapper around a pointer to the raw data.
60035b4 to
fa0e4e9
Compare
|
Okay, I've addressed all the things I felt weren't committable and modulo some rate-limiting all the tests have passed. I still don't feel 100% about this code but don't think I'll spend more time on improving it until someone complains :) |
carver
left a comment
There was a problem hiding this comment.
"pending" test is Circle/github rate-limit issue
LGTM!
@veox pointed out that some of the tests use a very large amount of memory. I did some profiling and found the biggest offenders. Here are the top 10, sorted from least to greatest. This number tracks total allocations (from tracemalloc), not maximum size in memory.
Most allocations came from a single line, which has now been changed:
with the requested memory, this created an often unnecessary copy of
the data. It now returns a memoryview(), which is a python wrapper
around a pointer to the raw data.
This caused the total number of allocated bytes to drop dramatically. The new set of top 10 offenders:
Total allocations is not the same as the high water mark of memory used but it was a lot easier for me to measure. To verify that this also helped the thing which actually matters I checked maxrss on some of the tests and saw a nice improvement:
static_Call1MB1024Calldepth_d1g0v0_Constantinopleused to consume 1.2 GB and now uses 705 MBstatic_Call50000_ecrec_d0g0v0_Constantinopleused to consume 3.8GB and now uses 1.4GBFuture work:
Cute Animal Picture
And alternative approach might be to make all the objects images of kittens, in which case any duplication would remain but gain unassailable justification: