From c28da40757d96a433dc02c17ea4c862632e7b72b Mon Sep 17 00:00:00 2001 From: Mick Cooney Date: Mon, 19 Oct 2026 12:31:12 +0100 Subject: [PATCH] docs(r): state the exportPattern remembered-name cap and fastestWithin's minimum rExportPatternMatches remembers at most 100,000 matched names per package, so past that a name reads as not exported once the budget is spent; say so in the function comment and the provider guide. fastestWithin always runs one attempt, even when tries is below 1; word the comment to match. --- docs/languages/r-provider.md | 2 +- gitnexus/src/core/ingestion/languages/r/package-config.ts | 4 +++- gitnexus/test/helpers/timing-attempts.ts | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/languages/r-provider.md b/docs/languages/r-provider.md index 7572400ee6..8ab2d443b5 100644 --- a/docs/languages/r-provider.md +++ b/docs/languages/r-provider.md @@ -122,7 +122,7 @@ Not supported: - Caps, in `linear-regex.ts`: `MAX_TOTAL_WORK` (40,000,000 state visits per matcher), `MAX_SHARED_WORK` (100,000,000 matching visits per load), `MAX_PACKAGE_WORK` (30,000,000 per package), `MAX_SHARED_STATES` (500,000 NFA states per load) and `MAX_PACKAGE_STATES` (100,000 per package); a single pattern is also capped by `MAX_PATTERN_LENGTH` (16,384 characters) and `MAX_STATES` (16,384). - A pattern refused after its NFA was partly built is charged for the build (eight visits per state or build step), and once the budget is spent later patterns are refused without being parsed (dropped, with a reason naming the work budget). A NAMESPACE of thousands of oversized patterns therefore spends the same budget as one of hostile matches. - Groups nested deeper than 256 (`MAX_NESTING`) are refused with the reason "groups are nested too deeply". The limit sits well inside the call stack (a quarter of the default stack still compiles 256 levels), so the verdict is the same cold or warm and on every machine. -- Once the work budget is spent the matchers are no longer asked. A name an `exportPattern()` matched while the budget lasted keeps that answer (a second definition of the same name stays exported); a name not decided by then reads as not exported (fail closed), and the cut-short patterns are named in a warning. +- Once the work budget is spent the matchers are no longer asked. A name an `exportPattern()` matched while the budget lasted keeps that answer (a second definition of the same name stays exported; only the first 100,000 distinct matched names per package are remembered, so past that a name reads as not exported once the budget is spent); a name not decided by then reads as not exported (fail closed), and the cut-short patterns are named in a warning. - A verdict answered from a matcher's memo (a name asked about again) costs one visit of the work budget, so many matchers asked about the same names over and over are bounded by the budget too. - A pattern that does not fit is dropped, exports nothing and is warned about: at most 50 patterns are named per package (`MAX_LISTED_DROPPED_PATTERNS`), followed by a summary line counting the rest. - The first pattern refused for lack of states closes that package's allowance, so later patterns in the package are refused without being parsed. diff --git a/gitnexus/src/core/ingestion/languages/r/package-config.ts b/gitnexus/src/core/ingestion/languages/r/package-config.ts index b2d4a4a851..805530cebd 100644 --- a/gitnexus/src/core/ingestion/languages/r/package-config.ts +++ b/gitnexus/src/core/ingestion/languages/r/package-config.ts @@ -126,7 +126,9 @@ const matchedWhileBudgetLasted = new WeakMap>(); * package's work budget (or the load's) is spent it stops asking the matchers, so the cost no * longer grows as patterns x names. A name it matched while the budget lasted keeps that * answer (one set lookup, so a duplicate-named definition does not flip from exported to - * private); a name it had not decided answers false, and the patterns it did not get to run are + * private), but only for the first {@link MAX_REMEMBERED_MATCHES} (100,000) distinct matched + * names per package: a name matched after that is not remembered and answers false once the + * budget is spent. A name it had not decided answers false, and the patterns it did not get to run are * then reported by {@link reportRExportPatternProblems}. */ export function rExportPatternMatches( diff --git a/gitnexus/test/helpers/timing-attempts.ts b/gitnexus/test/helpers/timing-attempts.ts index 771591d620..3c19c28117 100644 --- a/gitnexus/test/helpers/timing-attempts.ts +++ b/gitnexus/test/helpers/timing-attempts.ts @@ -19,8 +19,9 @@ export function timeWork(prepare: () => () => T): TimedAttempt { } /** - * Run `attempt` up to `tries` times, stopping at the first one within `budgetMs`. Returns the - * fastest attempt (the passing one, else the least slow), whose `ms` the caller asserts on. + * Run `attempt` at least once (a `tries` below 1 still runs one) and up to `tries` times, stopping + * at the first one within `budgetMs`. Returns the fastest attempt (the passing one, else the least + * slow), whose `ms` the caller asserts on. */ export function fastestWithin( budgetMs: number,