iris icon indicating copy to clipboard operation
iris copied to clipboard

Trial different memory profiler in benchmarks

Open pp-mo opened this issue 3 years ago • 6 comments

From work elsewhere, we find that it might be better to track Python heap usage, instead of Linux RSS space

At least the observation here ("When initially run, this claimed that no memory at all was used ") is relevant : It show that "RSS" is not working for a simple tests where a setup may allocate space that is then re-used within the tested operation -- but "tracemalloc" does seem to do that right.

pp-mo avatar Jul 29 '22 14:07 pp-mo

A really simple tracemalloc solution may look like this (thanks to @jamesp )

class MemoryMonitor:
    def __init__(self):
        self.memory_mb = None

    @contextmanager
    def context(self):
        """Measure the time+memory used by a codeblock."""
        tracemalloc.start()
        yield
        _, peak_mem = tracemalloc.get_traced_memory()
        tracemalloc.stop()
        self.memory_mb = peak_mem * 1.0 / 1024 ** 2

memmon = MemoryMonitor()
with memmon.context():
  op()
print(memmon.memory_mb)

(though syntax usage might be improved?)

pp-mo avatar Jul 29 '22 14:07 pp-mo

TODO : need to compare results with/without offline to assess. As @trexfeathers points out, you can't use ASV for this !

pp-mo avatar Jul 29 '22 14:07 pp-mo

In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity.

If this issue is still important to you, then please comment on this issue and the stale label will be removed.

Otherwise this issue will be automatically closed in 28 days time.

github-actions[bot] avatar Dec 12 '23 00:12 github-actions[bot]

This stale issue has been automatically closed due to a lack of community activity.

If you still care about this issue, then please either:

  • Re-open this issue, if you have sufficient permissions, or
  • Add a comment stating that this is still relevant and someone will re-open it on your behalf.

github-actions[bot] avatar Jan 09 '24 00:01 github-actions[bot]

Having used tracemalloc elsewhere, I'm increasingly convinced that it does offer a better solution. E.G. See #5753

pp-mo avatar Feb 23 '24 10:02 pp-mo

Having used tracemalloc elsewhere, I'm increasingly convinced that it does offer a better solution. E.G. See #5753

See now also : #5796

pp-mo avatar Mar 04 '24 10:03 pp-mo