Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Schema.isStringFinite (and Number string matching) takes quadratic time on long digit runs

Đang mở
#9,595 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@magoz đang làm issue này rồi.

Từ ngày 20/10/2026.

  • #9596 của @magoz — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
16.7k
Fork
808
Merge trung bình
10 giờ 12 phút
Pull request đã merge (30 ngày)
813

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.