Considering the language is still young, and the API is not very rich, what do you Mojo programmers use to profile your programs?
The methods I have tried with varying success are:
Manually measuring the runtime of every function with the time library (using perf_counter_ns() function). This option surely works but it is quite a hassle for a very big program.
Using /usr/bin/time to observe memory usage and general program runtime.
Using C API functions called with external_call FFI interface (one such example is POSIX clock_gettime) then doing the same thing as (1) (it’s the same thing, but it can be more accurate depending on the situation?).
Using profilers such as perf or valgrind. This does show some interesting and useful output, with Mojo symbols and function names showing up, but for some reason, I can only get it to show the time spent in functions up to a certain depth, which is really limiting due to the levels of indirection in my program.
I would also like to raise the question of whether or not the standard library is also profiled during development, and if so, then how. Perhaps this could give insight into optimizing our Mojo programs.
Are you compiling with debug symbols (-g)? That makes perf behave much better, and perf-based tools work pretty well for my Mojo code when those are enabled.
The standard library is mostly handled via micro-benchmarks, but it’s also relatively simple at the moment and there are still low hanging algorithmic improvements for some things awaiting new language features to make them work nicely.
I have used the debug symbols -g option of course. But for me, both perf and valgrind show that most of the time spent in my program is in a single function (which calls many other functions, so there clearly is something wrong with regards to function depth in this case. I am not sure why).
Mojo has both a very good optimizer and is fairly aggressive about inlining since it essentially performs LTO by default. I’ve found looking at compiler explorer more reliable if you’re not looking for a high level “about where is my time going?”.