Skip to content

Studio: skip the audio gallery prune's sidecar pass under both caps and list prepared inputs once per sweep - #15874

Merged
danielhanchen merged 5 commits into
mainfrom
perf/audiogal
Oct 29, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
perf/audiogal

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What changes

Two cleanup paths in the Studio audio stack stop repeating work that cannot change their result.

  1. audio_gallery._prune_to_cap runs after every saved TTS clip. It parsed every sidecar, built a full record per clip, sorted, then summed sizes, only to find that nothing was over either cap (the usual case below 2000 clips and 5 GiB). It now first lists the clip WAVs in the folder it locked and, if their count fits the clip cap and their WAV plus .source.wav bytes fit the byte cap, returns 0 without reading any sidecar. The clips the prune ranks are a subset of those WAVs (owned, not archived, not pinned), so when every WAV fits, the subset fits and main would also remove nothing. The size sum stops as soon as it passes the byte cap. Over a cap, the existing path runs unchanged.
  2. audio_inputs.sweep sized each live upload by globbing {id}.*.wav once per input, one directory listing per input. It now lists the folder once and maps each name to the part before its first dot (an input id has no dot, so that is exactly the glob's match). Case folding follows pathlib's glob on the platform (os.path.normcase); stems that are not id-shaped, and any non-ASCII name on a case-insensitive platform, use the old per-input glob. Removals still glob at removal time, so an expired or evicted input still takes every prepared copy that exists when it is removed.

No change to what is kept or deleted, the return values, or the log lines.

Results

Deterministic counts on the same fixtures, base = merge base, head = this branch (5 repeats each, wall time median with min to max in brackets; A/A = base run twice).

Case Sidecar reads Glob calls stat calls Base ms Head ms
Prune, 1999 clips, default caps 1999 to 0 1 to 1 19993 to 3999 273 (268 to 346) 35 (33 to 47)
Prune, 2001 clips, cap 2000 4003 to 4003 2 to 3 22016 to 22016 381 (372 to 398) 375 (361 to 398)
Prune, byte cap binds (500 clips) 1250 to 1250 2 to 3 5953 to 6523 116 (115 to 117) 129 (124 to 139)
Sweep, 500 inputs x 3 copies, all live 500 to 500 501 to 1 4505 to 4505 450 (429 to 479) 44 (44 to 51)
Sweep, same, byte cap evicts 233 500 to 500 734 to 234 3573 to 3573 595 (580 to 635) 212 (209 to 251)
Sweep, same, every 7th expired 500 to 500 501 to 73 3929 to 3929 414 (399 to 452) 102 (98 to 104)

A/A spread on the base arm: the byte-cap prune case moved 116 to 135 ms between two base runs, so its +13 ms on head (one extra listing and 570 stat calls before the existing path) is inside noise. Every case leaves an identical file set (hash of the remaining names) and returns the same count on both arms.

Tests

  • New tests/test_audio_gallery_prune_caps.py: a prune under both caps reads no sidecar (fails on main, passes here); just over the clip cap, the byte cap, and the byte cap counting a .source.wav still remove the oldest clip.
  • New in tests/test_audio_inputs.py: a sweep over live inputs does no per-input glob (fails on main); the single listing gives the same prepared copies as the per-input glob for neighbours such as aaaa / aaaab, aaaa..wav, aaaa.x.y.wav, aaaa.1.wav.tmp, cc-dd_1x.1.wav, and the byte cap evicts the same input.
  • Fuzz of the listing against Path.glob (300 random folders, names with [, *, ?, upper case, non-ASCII, empty middles) on Python 3.9, 3.10, 3.11, 3.12, 3.13 and 3.14: 0 mismatches.
  • Differential prune check: 150 seeded galleries (pinned, archived, grouped, sidecar-less and orphan WAVs, .source.wav copies), each pruned at 13 cap settings around the exact clip count and byte total (one under, exactly at, one over, both caps): all 1,867 cases leave the same files and return the same count on main and this branch, 283 of them with deletions.
  • Every backend test file that touches audio_gallery, audio_inputs or gallery_flags (29 files): main 1124 passed, 1 skipped; this branch 1130 passed, 1 skipped (the 6 new tests).
  • py_compile on Python 3.9 and 3.10.

Not covered

  • Windows and macOS were not run. On Windows the listing folds case with os.path.normcase like pathlib's glob for ASCII names and falls back to the per-input glob when a non-ASCII name is present.
  • The race where audio_gallery re-resolves its folder mid-operation is fixed separately (fix/audiogal-dir); the new check here only uses the folder the prune locked. The two branches merge cleanly.
  • transcript_gallery.py has no cap or per-item listing, so it is unchanged.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-29T12:13:05.886287Z b4ba816 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 417b4ec8e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen marked this pull request as ready for review October 29, 2026 12:12
# Conflicts:
#	studio/backend/tests/test_audio_inputs.py
@danielhanchen
danielhanchen merged commit df42bc0 into main Oct 29, 2026
1 of 37 checks passed
@danielhanchen
danielhanchen deleted the perf/audiogal branch October 29, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant