Skip to content

Key globs with many stars take seconds to match - #1283

Merged
theoephraim merged 1 commit into
dmno-dev:mainfrom
voiys:fix-glob-backtracking
Nov 13, 2026
Merged

theoephraim merged 1 commit into
dmno-dev:mainfrom
voiys:fix-glob-backtracking

Conversation

@voiys

@voiys voiys commented Nov 9, 2026

Copy link
Copy Markdown
Contributor
# .env.schema
# @import(./.env.shared, pick=[*A*A*A*A*A*A*A*B])
# ---
PORT=3000

# .env.shared
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=1      (50 x A)

$ time varlock load
main:  2.2 s
here:  0.07 s

one more star and ten more A's is about a minute on main.

cause: globToRegExp turns the glob into /^.*A.*A.*A.*A.*A.*A.*A.*B$/. when it doesn't match, the regex tries every way to split the key between the stars.

fix: match with a loop that only ever goes back to the last star (compileGlob). it gives the same answers as the regex: i compared the two on 300k random pattern/key pairs.

the same function is behind --filter, @setValuesBulk pick/omit and @auditIgnoreKeys.

context: found by feeding generated and deliberately hostile schemas to a language server prototype (#469). nobody writes eight stars by accident, so this is a stretch for normal use. it matters to anything that loads a schema it didn't write, like an editor opening a cloned repo.

test: glob.test.ts. the 7-star case has to finish in under 100 ms.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes: Reviewed the matcher replacement and all affected filtering paths.

  • Glob matching: Replaces backtracking regexes with a loop that retries only the most recent star.
  • Consumers: Updates shared item filters and @auditIgnoreKeys to use the new matcher.
  • Regression coverage: Adds matching and performance tests; 182 focused tests passed, and 1,331,946 short pattern/key comparisons agreed with the previous implementation.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

A key glob compiled to a regex like ^.*A.*A.*A$, which backtracks
polynomially in the number of stars: 7 stars against one 50-character key
took 2 seconds, 8 stars about a minute. The matcher is now a loop that
goes back to the most recent star only.
@theoephraim
theoephraim force-pushed the fix-glob-backtracking branch from e722e4d to d027ee3 Compare November 13, 2026 00:47
@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@1283

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@1283

@varlock/cloudflare-integration

npm i https://pkg.pr.new/@varlock/cloudflare-integration@1283

@varlock/nextjs-integration

npm i https://pkg.pr.new/@varlock/nextjs-integration@1283

@varlock/nuxt-integration

npm i https://pkg.pr.new/@varlock/nuxt-integration@1283

@varlock/vite-integration

npm i https://pkg.pr.new/@varlock/vite-integration@1283

@varlock/1password-plugin

npm i https://pkg.pr.new/@varlock/1password-plugin@1283

@varlock/aws-secrets-plugin

npm i https://pkg.pr.new/@varlock/aws-secrets-plugin@1283

@varlock/azure-key-vault-plugin

npm i https://pkg.pr.new/@varlock/azure-key-vault-plugin@1283

@varlock/bitwarden-plugin

npm i https://pkg.pr.new/@varlock/bitwarden-plugin@1283

@varlock/keepass-plugin

npm i https://pkg.pr.new/@varlock/keepass-plugin@1283

@varlock/pass-plugin

npm i https://pkg.pr.new/@varlock/pass-plugin@1283

@varlock/proton-pass-plugin

npm i https://pkg.pr.new/@varlock/proton-pass-plugin@1283

commit: d027ee3

@theoephraim
theoephraim merged commit 810d9b6 into dmno-dev:main Nov 13, 2026
26 checks passed
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.

2 participants