Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf (AptDat): Replaced our default usage of AptDatLine everywhere wi…
…th str This is unfortunately a potentially breaking change, but it cuts the time to read X-Plane's 35k+ airport default apt.dat down from ~148 seconds to under 32 seconds on my 2019 MacBook Pro! The major bottleneck here was the memory allocator---looking at a perf trace, more than 50% of the parsing time was spent in AptDatLine.__init__!
- Loading branch information
Showing
6 changed files
with
253 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import gc | ||
import timeit | ||
from xplane_airports.AptDat import AptDat | ||
from pathlib import Path | ||
|
||
xplane_installation = Path('/Users/tyler/design') | ||
assert xplane_installation.is_dir(), f"{xplane_installation} does not exist or is not a directory" | ||
|
||
iterations = 3 | ||
print(f"Repeating {iterations} iterations of parsing 35,000+ airports from disk (this will take awhile)") | ||
|
||
# Tyler observes: We can't just run a bunch of iterations using timeit(), because it disables GC, | ||
# and we use gigabytes of RAM per parse of our giant files. | ||
# | ||
# It's not realistic to benchmark us parsing multiple 300 MB files... there are only so many airports in the world! | ||
total_seconds = 0 | ||
for i in range(iterations): | ||
total_seconds += timeit.timeit(lambda: AptDat(xplane_installation / 'Resources/default scenery/default apt dat/Earth nav data/apt.dat'), number=1) | ||
gc.collect() | ||
|
||
print(f"Average time over {iterations} runs: {total_seconds / iterations}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.