psyinfra / onyo

text-based inventory system on top of git
ISC License
3 stars 5 forks source link

NF: replace `tree` with python implementation #605

Closed aqw closed 4 months ago

aqw commented 4 months ago

This implementation mimics the original behavior, while fixing two bugs:

By using pure Python, we gain flexibility to add Onyo-specific features (perhaps asset highlighting, etc) and also drop a dependency (albeit a common one).

We never allowed passing flags to tree, so there really is no loss in functionality.

I did some primitive performance tests.

32 directories, 42 files:
-            tree  0.00s user 0.00s system 87% cpu 0.005 total
- (old) onyo tree  0.09s user 0.01s system 99% cpu 0.094 total
- (new) onyo tree  0.09s user 0.01s system 99% cpu 0.101 total
1844 directories, 9706 files
-            tree  0.06s user 0.03s system 99%  cpu 0.090 total
- (old) onyo tree  0.12s user 0.05s system 106% cpu 0.164 total
- (new) onyo tree  1.21s user 0.08s system 100% cpu 1.289 total

In the "normal" use case, where someone prints a tree of a size that a human can reasonably read, the performance hit is negligible.

However, large trees do suffer from a noticeable performance impact. This can be dropped to 0.43s if all output is printed at once.

1844 directories, 9706 files
- onyo tree  0.38s user 0.07s system 102% cpu 0.435 total
codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.70%. Comparing base (dc2348d) to head (a68ded3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #605 +/- ## ========================================== + Coverage 95.68% 95.70% +0.01% ========================================== Files 71 71 Lines 5586 5608 +22 Branches 1090 1097 +7 ========================================== + Hits 5345 5367 +22 Misses 141 141 Partials 100 100 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.