perf: compile remote match patterns once instead of per-request #88

Merged
benvin merged 1 commits from benvin/compile-patterns-once into master 2026-07-02 20:20:01 +10:00
Owner

Fixes #73

Why

Classifier.Classify runs on every proxied request and recompiled the Blocklist/Patterns/Immutable/Mutable regex lists each time. Regex compilation is expensive and fully redundant.

Changes

  • Memoise compilation in a sync.Map keyed by pattern text (compileCached); each distinct pattern compiles once and is reused. Patterns that fail to compile are cached as a typed nil so they are not retried. No invalidation needed since the pattern text is the key.

Validation

  • go test ./internal/proxy/ and make e2e pass.
Fixes #73 ## Why `Classifier.Classify` runs on every proxied request and recompiled the Blocklist/Patterns/Immutable/Mutable regex lists each time. Regex compilation is expensive and fully redundant. ## Changes - Memoise compilation in a `sync.Map` keyed by pattern text (`compileCached`); each distinct pattern compiles once and is reused. Patterns that fail to compile are cached as a typed nil so they are not retried. No invalidation needed since the pattern text is the key. ## Validation - `go test ./internal/proxy/` and `make e2e` pass.
unkinben added 1 commit 2026-07-02 00:33:48 +10:00
perf: memoise regex compilation in the classifier
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
b698d1bdc0
Classify runs on every proxied request and recompiled each remote's
pattern lists every time. Cache compiled regexes keyed by pattern text so
each distinct pattern compiles once and is reused thereafter.

Refs #73
benvin merged commit 61a1a99112 into master 2026-07-02 20:20:01 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#88