adamchainz / django-perf-rec

Keep detailed records of the performance of your Django code.
MIT License
347 stars 25 forks source link

Optimize sql_fingerprint() a bit #601

Closed adamchainz closed 7 months ago

adamchainz commented 7 months ago

Grabbed a bunch of queries and timed in IPython with:

In [1]: from django_perf_rec.sql import sql_fingerprint ; from example import queries

In [2]: %%timeit
   ...: sql_fingerprint.cache_clear()
   ...: for query in queries:
   ...:     sql_fingerprint(query)
   ...:
   ...:     sql_fingerprint(query, hide_columns=False)
   ...:
47.7 ms ± 92.8 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

Applied some easy, obvious optimizations from reading the code, and the same took 46.9ms instead, again with tight variance. That’s ~1ms faster, or ~2%.