Skip to content

perf(platform): index approved OAuth assets by content tuple - #556

Merged
cpojer merged 2 commits into
voidzero-dev:mainfrom
yangshun:codex/oauth-asset-validation-index
Oct 23, 2026
Merged

cpojer merged 2 commits into
voidzero-dev:mainfrom
yangshun:codex/oauth-asset-validation-index

Conversation

@yangshun

@yangshun yangshun commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Issue

OAuth upload validation currently scans every approved asset for each requested asset while holding the project lock. At the allowed 5,000-asset batch size, this can require millions of comparisons.

Fix

This reduces validation from O(approved × requested) to expected O(approved + requested).

Build a Set of approved (blake3, md5, size) tuples, using a local assetApprovalKey() helper with JSON.stringify for both indexing and lookup. Project matching and exact matching of all three fields are preserved.

Benchmark results

12 paired runs on Apple M2 Pro, Node v24.21.0. Validation timings include Set construction and JSON encoding; database, presigning, and network I/O are excluded.

Approved assets Requested assets Before After % reduction
100 100 0.084 ms 0.051 ms 39.1%
5,000 100 4.721 ms 2.082 ms 55.9%
5,000 1,000 40.969 ms 2.317 ms 94.3%
5,000 5,000 227.016 ms 3.340 ms 98.5%
20,000 5,000 808.418 ms 10.352 ms 98.7%

The 5,000/5,000 case is about 68× faster.

Why the tests changed

Expanded coverage verifies multiple approved assets, reordered batches, duplicates, mismatched fields, mixed valid/invalid batches, and strict field types ("3" versus 3). All 19 tests pass against both the original and optimized implementations.

Verification

Typechecking passed; 4,447 affected tests and 14,496 full-suite tests passed.

@yangshun
yangshun marked this pull request as draft October 23, 2026 00:35
@yangshun
yangshun marked this pull request as ready for review October 23, 2026 01:03

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ridiculous. Sorry for the slop, and thanks for the fix!

@cpojer
cpojer merged commit 6d0cbf4 into voidzero-dev:main Oct 23, 2026
2 checks passed
@yangshun
yangshun deleted the codex/oauth-asset-validation-index branch October 23, 2026 01:24
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.

2 participants