Schema.isStringFinite (and Number string matching) takes quadratic time on long digit runs
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 66/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- backend
Direzione di ricerca
The report identifies FINITE_PATTERN and the affected paths: Schema.isStringFinite(), number decoding, record keys, and template literals. Start by searching the schema implementation and tests for FINITE_PATTERN and the number string matching variants, then run the relevant tests with the reported long digit runs. Done when invalid inputs are rejected in linear time across the listed paths and existing number parsing behavior still passes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What version of Effect is running?
Current main (bbedfc71c0)
What steps can reproduce the bug?
import { Schema } from "effect"
const is = Schema.is(Schema.String.check(Schema.isStringFinite()))
for (const n of [5_000, 10_000, 20_000, 40_000]) {
const input = "1".repeat(n) + "x"
const start = performance.now()
is(input) // false
console.log(n, Math.round(performance.now() - start), "ms")
}
What is the expected behavior?
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:
| Path | 40k chars |
|---|---|
Schema.isStringFinite() |
729 ms |
Schema.toCodecStringTree(Schema.Struct({ n: Schema.Number })) decoding { n: input } |
640 ms |
Schema.Record(Schema.Number, Schema.String) decoding { [input]: "v" } |
491 ms |
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.
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 10h 12m
- PR unite (30g)
- 813
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Effect-TS/effect
-
BrowserWorkerRunner: port finalizer throws when the worker global has no close() (Bun)Forse già presa @santiago-ramos-02 l’ha presa 20 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Effect-TS/effect#8635 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Support {self: this} for fnUntracedForse di nuovo libera @ArjunCodess l’ha presa 31 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Effect-TS/effect#8101 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 32/100
Effect-TS/effect#9610 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Schema.isBase64 / isBase64Url throw RangeError on multi-megabyte stringsForse già presa @magoz l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 20/100
I maintainer di solito rispondono entro 1 giorno
-
PersistedQueue SQL store: a stale handler's retry releases the newer claim its own worker made, so the element is delivered again while in flightForse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#9591 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
diegosouzapw/OmniRoute#17386 ·
I maintainer di solito rispondono entro 1 giorno
-
ready-for-agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
area/dashboard kind/bug kind/bug-qa QA/dev-automation
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
vybestack/llxprt-code#3917 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
api-parity
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
IBM/carbon-components-ember#1157 ·
I maintainer di solito rispondono entro 1 giorno