JamesHutchison / pytest-hot-reloading

A hot reloading pytest daemon, implemented as a plugin
MIT License
86 stars 2 forks source link

Performance improvements related to `best_effort_copy` #57

Closed JamesHutchison closed 8 months ago

JamesHutchison commented 8 months ago

This updates the best_effort_copy logic to do less copying. I noticed when running a large group of tests, that there was a substantial delay before testing actually started. Digging into it and randomly pausing during this period, I added whatever was being copied to a list to not copy until the time was reduced by quite a bit. The only exception seemed to be _request which would result in errors after a couple reruns. Since _request was a deep object, I added a code path for forcing a limited depth copy.

It's been a while since I worked on this, but the background, if I remember correctly:

Testing the performance, the improvement is substantial. Using the tests in this repo as a reference:

The failing test invokes more logic, exception handling, and introspection (errors are slow...) so it taking longer makes sense in this case. I disabled the check logic and its getting 6.6 seconds. I wouldn't expect an initial run with the daemon to be faster than without, so its worth calling out this is curious behavior and may indicate something is not quite right.

JamesHutchison commented 8 months ago

I wouldn't expect an initial run with the daemon to be faster than without, so its worth calling out this is curious behavior and may indicate something is not quite right.

This can be explained by xdist set-up time and other logic that isn't shortcut when you use the client, so actually this makes sense. When you disable xdist on this repo the time difference is smaller