[Feature Request] Memory allocation watcher #2725
Labels
enhancement
New feature or request
Initiative: Compilation/Execution
mojo-repo
Tag all issues with this label
Review Mojo's priorities
What is your request?
Description
As a developer using Mojo, I would like to be able to unit test the number of allocations made by a function, maybe similar to how Julia's
@time
macro allows for measuring allocations.Proposed Implementation
One possible implementation of this feature could be the addition of a new
@allocations
macro, which would allow developers to assert the number of allocations made by a function in a unit test. Below are some possible ways to express this. I'm not sure if either of these are the best, and readers are encouraged to contribute ideas of their own!Edit: Option 4 is my favourite so far
Option 1: if Mojo has macros
Option 2: A pythonic take using
with
[edit from feedback] Option 3: Same as option 2 but without strings
[Another edit 5/22/24] Option 4: Most flexibility with allocation values
What is your motivation for this change?
Currently, when writing performance-critical code, developers often have to rely on other tools (e.g. xctrace on macos) to measure allocations and ensure that they are minimized. But these tools are not standard across platforms. Having the ability to assert the number of allocations in unit tests would
Any other details?
Julia's
@time
macro in actionThe text was updated successfully, but these errors were encountered: