You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Schema.isStringFinite (and Number string matching) takes quadratic time on long digit runs #9595
Rejecting the string takes time linear in its length (a few ms at 40k chars).
What do you see instead?
Quadratic time (Node v24.21.0): 12 ms, 47 ms, 163 ms, 751 ms. Each doubling of n makes it ~4× slower; 80k chars take ~2.8 s.
Additional information
The bare regex shows the same times, so the problem is FINITE_PATTERN ([+-]?\d*\.?\d+(?:[Ee][+-]?\d+)?): for a run of digits not followed by a valid ending, \d* and \d+ retry every split of the run.
/^[+-]?\d*\.?\d+(?:[Ee][+-]?\d+)?$/.test("1".repeat(40_000)+"x")// ~700 ms
The same regex (or its Infinity|-Infinity|NaN variant) runs in other places. Each was ~4× slower per doubling up to 40k chars:
Schema.TemplateLiteral(["a", Schema.Number]) checking "a" + input
717 ms
Inputs that trigger it: "1".repeat(n) followed by "x", ".", "e" or ".1x", and the same with a leading -. "." + "1".repeat(n) + "x" and "1e" + "1".repeat(n) + "x" stay fast. Valid digit runs are fast too. Schema.NumberFromString does not use the regex and is not affected.
Activity