Skip to content

perf: recognise identical files before parsing them - #26

Merged
danielededo merged 1 commit into
mainfrom
perf/skip-parsing-known-files
Oct 11, 2026
Merged

danielededo merged 1 commit into
mainfrom
perf/skip-parsing-known-files

Conversation

@danielededo

Copy link
Copy Markdown
Owner

store_workout parsed each file before checking whether its exact bytes were already stored. Parsing is most of what a file costs, so sending an export a second time took as long as the first import while storing nothing.

  • Split find_duplicate into find_identical (hash only, checked before parsing) and find_same_session (needs the parsed file, as before).
  • New test: an identical file is reported as a duplicate without the parser being called. It fails on main.
  • docs/DESIGN.md: one paragraph on why the hash is checked first.

Measured with 150 synthetic Garmin-style FIT activities (1 Hz, avg 131 KB, 11 MB zipped) on PostgreSQL 16, calling store_archive directly:

before after
Second import, all 150 duplicates 130 s 0.7 s

The first import is unchanged (about 1–1.6 s per activity), so a large export still exceeds nginx's 120 s timeout; that is fixed separately by importing archives in the background.

Checks: ruff lint and format, pytest 345 passed, coverage 96.5%.

store_workout parsed every file before asking whether its exact bytes were
already stored. Parsing is most of a file's cost, so re-sending an export
spent as long as the first import storing nothing: 130 s for 150 FIT
activities, enough on its own to hit nginx's 120 s timeout. Check the hash
first, then parse only for the same-session check. The retry now takes 0.7 s.
@danielededo
danielededo merged commit 35e6404 into main Oct 11, 2026
5 checks passed
@danielededo
danielededo deleted the perf/skip-parsing-known-files branch October 11, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant