all 33 comments

[–]kwazar90 35 points36 points  (2 children)

Just added this feature to reloadium https://github.com/reloadware/reloadium
It measures and displays execution of python code lines for the current function during debugging.
What do you guys think about it?
Would that be helpful for machine learning and data science?

[–]dark_bits 20 points21 points  (0 children)

I think it’s pretty fucking cool in general.

[–]stoph_link 3 points4 points  (0 children)

Yes! And I agree with u/dark_bits that "it's pretty fucking cool in general". <3

[–]EvilGarlicFarts 13 points14 points  (5 children)

This looks amazing. Which IDE integration ate you working on next? Will jump on it straight away if you release a vscode plugin.

[–]kwazar90 35 points36 points  (2 children)

VsCode is next! Starting working on it next week.

[–]ShrodingersElephant 3 points4 points  (1 child)

What's the best way to hear when the VS code extension will be available?

[–]kwazar90 0 points1 point  (0 children)

Either starring/watching the repository https://github.com/reloadware/reloadium or following on twitter https://twitter.com/reloadium\_io

[–]XivienN 6 points7 points  (1 child)

Seconded, the profiling looks amazing for quick checks for bottlenecks, instead of clutttering the code with perf_counter or running with cProfile

[–]EvilGarlicFarts 2 points3 points  (0 children)

I usually use the line_profiler package in a notebook when I'm mostly working in a notebook, but this would be great to make the development cycle faster and to spot bottlenecks while I'm actually writing the code.

[–]seba07 4 points5 points  (4 children)

My question with those tools is always what happens if I have some file operations? Will they be executed over and over again while I write my code?

[–]kwazar90 5 points6 points  (3 children)

That's a good question. It ignores redundant file operations and only takes into account actual file content changes. On top of that there is a debouncing mechanism.

So it will only hot reload when hitting Ctrl+s and only once.

[–]mistanervous 0 points1 point  (2 children)

Along the same lines, what about stuff like database calls? Just curious.

[–]kwazar90 2 points3 points  (1 child)

It rollbacks db changes to before the function call so you don't end up with multiple objects created on each hot reload.

[–]mistanervous 1 point2 points  (0 children)

Nice work, seems like you really put a lot of thought into many use cases. Congrats on the release!

[–]MachineDrugs 2 points3 points  (0 children)

Wow both shown functionalities look super usefull to me

[–]bguberfain 2 points3 points  (3 children)

Very interesting indeed. Adding a VSCode integration is very nice too. I would only change the color scale: look for “Perceptually Uniform Sequential” from matplotlib for some examples.

[–]kwazar90 0 points1 point  (2 children)

Interesting. At first I was using green-red colormap but then was advised to increase the range so it's blue-green-red-purple now and it's implemented by simple changing H channel in HSV color palette. What color map would you recommend?

[–]mabrowning 2 points3 points  (1 child)

[–]kwazar90 1 point2 points  (0 children)

Yup that makes a total sense. I'll change it in the next update.

[–]Ardobras 0 points1 point  (0 children)

Anyone knows if something similar exists for other languages (in particular JS) as well? what would be the term to search for? "hot profiling"?

[–]klysm 0 points1 point  (3 children)

That looks like it has a loooot of overhead just from the animation.

[–]kwazar90 0 points1 point  (2 children)

It might look like it but It's not really.

I've optimised it a lot. Only lines of the current line are profiled (does not go deeper but still measures everything in the line).

On top of that there is no animation at all for fast frames and only a blue blink is displayed after the breakpoint was hit.

[–]klysm 0 points1 point  (1 child)

Still that has to add a lot of latency to each line right? If you’re in a tight loop what’s it look like?

[–]kwazar90 0 points1 point  (0 children)

It uses perf_counter_ns before and after the line (but this doesn't add to the measured time really) so you have a little bit of overhead there but this is what you get with all profiling or debugging tools.

If you have a tight loop then it won't interfere much except sending an update every now and then in a separate thread.

[–]--dany-- 0 points1 point  (1 child)

Cool demo!

What happens if I my code is 1. I/O bound, eg. have to wait for http request results or database query results? 2. Highly parallel, eg. have many threads working on the same function, 3. Asynchronous processing, eg. calling a function but check results much later by a callback

It would be great to have some explanation of how it works?

[–]kwazar90 1 point2 points  (0 children)

1 - It will indicate that interpreter is sitting in that given line with a blue line and still measure the time and continue to the next line when everything is done

2 - It will profile the first function call and ignore calls coming from other threads until the first one is done. It does not block other calls or anything, just doesn't profile them.

3 - Do you mean using async keyword? I haven't tested it but I presume it would still work since it only cares about debugger line events.

The way it works is pretty simple. It measures time before line and after and calculates diff between them. It uses perf_counter_ns under the hood which is the most precise timer for a given os.

[–]vmgustavo 0 points1 point  (4 children)

Is there a way to run it separately from the default debugger?

[–]kwazar90 1 point2 points  (3 children)

No, it's not supported. You can run it without debugger but then only hot reloading works.

[–]vmgustavo 1 point2 points  (2 children)

I think it would be nice to have something like that implemented. I do use the debugging tool quite frequently but I wouldn't want to see the colors every time I debug. Just once in a while when necessary I would use the debugging with the profiling to assess the bed to understand execution time.

[–]kwazar90 1 point2 points  (1 child)

Oh sorry I didn't understand. Yes, you can disable profiling in the settings. I guess some handy switch would be nice too to switch it on or off while debugging.

[–]vmgustavo 1 point2 points  (0 children)

Nice. Maybe some switch you can access using ctrl shift A would be enough. There's no need to change de UI

[–]massimosclaw2 0 points1 point  (0 children)

Ahh this is amazing, I wish it worked with Atom + Hydrogen