Schema.isStringFinite (and Number string matching) takes quadratic time on long digit runs
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 66/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16.7k
- Forks
- 808
- Merge medio
- 10 h 7 min
- PR fusionados (30 d)
- 808
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Effect-TS/effect
-
Support {self: this} for fnUntracedPosiblemente ocupada @ArjunCodess la tomó hace 32 días. Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Effect-TS/effect#8101 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
v4 Cache.get: a caller that joins an abandoned lookup fails with an interruption it did not ask forAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
Los mantenedores suelen responder en 1 día
-
Typed unix socket and TLS options for `BunHttpClient` and `DenoHttpClient`Posiblemente ocupada @effect-bot la tomó hace 1 día. Abiertodocker-made-me-do-it enhancement platform
Effect-TS/effect#9687 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
RFC 9457 Problem Details for HttpApi errorsPosiblemente ocupada @effect-bot la tomó hoy. Abiertodocker-made-me-do-it enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
Los mantenedores suelen responder en 1 día
Todos los issues de Effect-TS/effect
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
chaitin/MonkeyCode#1437 ·
Los mantenedores suelen responder en 1 día
-
rtdb-info-connected-order test: unhandled 'connection is closed' rejection fails the CLI suiteAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
carbon-design-system/carbon-ai-chat#2615 ·
Los mantenedores suelen responder en 1 día
-
e2e-failure ready-to-code
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
redhat-developer/rhdh-plugin-export-overlays#4486 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug]: fileUploadMatrix.test.ts URL case does a real DNS lookup and fails offlinePosiblemente ocupada @r2jaff la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ComposioHQ/composio#5054 ·
Los mantenedores suelen responder en 1 día