Repository navigation
perf(typia): reuse pattern regexes and shortcut length checks - #2523
Conversation
samchon
left a comment
There was a problem hiding this comment.
Self-Review round 1 — source snapshot 1d80a78 (13 changed files; lockfile SHA-256 a33260663877a0c0c2889ad1e691bebdb49d864990f2846fd615cbc3e9297377).
Inspected the entire diff and its consumers: native string/tag/JSDoc lowering, file-level import insertion, CJS/ESM binding and early module calls, code-point runtime helpers, test discovery and fixture ownership, Evidence selection, published native-source inclusion, and the matching guide. Checked lazy invalid-pattern failure/retry, flag-free sharing and bounded retention, custom expressions/flags, generated-name collisions, nil/standalone importer behavior, numeric and Unicode length boundaries, and both compiler lines' existing CI gates.
The core installed-compiler CJS/ESM regression and 301 portable unit cases passed. The unchanged native regression fails against the original generator; original/current length probes distinguish 23→0 and 3→0 iterator steps. Full local and remote matrices remain in progress; the first parallel local attempt exhausted host memory and is being replaced by the same case populations at bounded concurrency.
Accepted finishing improvements: describe reuse after successful construction (a nonmatching string also initializes the regex), correct the E2E acknowledgment to reflect one compiler/child per target, retain compact JSON array formatting, and apply the repository's final formatter gate. No verified runtime correctness finding survived this source inspection. This is not a clean final review: full Windows verification, Ubuntu TypeScript 7.0/7.1 and race lanes, packaging/website CI and the fresh review of the final formatted head remain required.
samchon
left a comment
There was a problem hiding this comment.
Round-1 follow-up on the same 1d80a78 source snapshot: all first CI workflows settled. Build (including Evidence and benchmark compilation), experiments packaging, website and spelling passed. Test lanes failed in the new ES2019 fixture because its default lib omits BigInt64Array/BigUint64Array required by workspace source declarations; retain the repository's modern type libraries while varying emitted target. The remaining CI failure is the deferred formatter gate.
Further checking found a real issue in the new standalone fallback: without an emit context, the slot name is a plain __pattern_0 identifier. A source already declaring that identifier receives a conflicting var declaration; the exact generated slot and JavaScript redeclaration SyntaxError were reproduced. The correction will preserve the existing inline expression when compiler collision information is unavailable, and use compiler-generated names in the normal native host path. This removes the unsafe fallback naming assumption rather than adding a reserved-name exception.
The complete bounded-concurrency local round is still finishing its Go and Evidence populations. No source changes have been made during that round; its workspace population finished with nine passing workspaces and the same ES2019 fixture failure. After the batch correction and final formatter, a fresh whole-surface Self-Review and the full CI matrix are required.
samchon
left a comment
There was a problem hiding this comment.
Self-Review round 2 (solo), frozen head add08507a9b2ff23bb900521b33b5d9f81d72210, base ae0e985fd31e2a89e1862626020ee38f19104e07.
Lockfile SHA-256: 95454f0c39063f0af8227776995b2e84351179e431043b870a7f134574689c33. Provisioning is the pinned pnpm 10.6.4 workspace; the supported compiler matrix is TypeScript 7.0 and 7.1 with ttsc 0.34.1, Node 24 and Go 1.27. Local execution is Windows; clean CI consumers run on Ubuntu.
The preceding inspection identified two additional causes and repaired them together: standalone AST emission cannot allocate collision-safe bindings, so it now preserves the inline constructor; template-tag checks had separate lowering sites, so all standard string-tag paths now use the common lowering. The expanded template regression failed with 926 constructions before the latter repair and requires exactly one afterward. ES2019 fixtures also explicitly select the library declarations independently of output syntax. Acorn checks the actual output grammar rather than relying on modern Node to reject newer syntax.
Fresh whole-surface inspection covered all 17 changed files and their hunks, existing importer and file-transform integration, ordinary and template tag consumers, public Pattern metadata, runtime-helper exports, test discovery, dependency/catalog/lock wiring, Evidence selection, packaging, CI and documentation. No additional verified defect or sound improvement remained.
Coverage includes direct/factory/assert/validate/JSDoc/array/key checks; whole-template tags and unions; captured placeholders, placeholder unions and adjacent-placeholder backtracking; positive and negative verdicts; empty, escaped and invalid sources; failed-construction retries; custom predicates and stateful flags; generated-name collisions; early CJS calls and actual ESM cycles; CJS and ESM under ES2019 and ES2022 grammar; ASCII, astral code points, unpaired surrogates, combining marks and negative/fractional/infinite/NaN length bounds. Per-file ownership, deterministic first-use ordering, lazy initialization, module-lifetime retention and distinct-program concurrency were traced. Public types and schema output are unchanged.
Validation on this exact head:
- Root
pnpm format: passed. - All six PR workflows: passed, including both TypeScript consumer lanes, both Go compiler trees, native internals and distinct-program race checks, Evidence, build, packed experiments, website, spelling and formatting.
- Local complete serial package population: passed, including the new pattern/module regression and all 301 portable utility unit tests.
- Local uncached public/native Go trees (
go -C packages/typia/test test -count=1 -timeout=30m ./... ../native/...): passed. - Local full
pnpm evidencepopulation: passed with zero errors and warnings.
Round status: COMPLETE, CLEAN. The website build was verified in clean CI; the unrelated dirty sibling ttsc checkout was left untouched. The tracked working tree remains clean and the frozen head and lockfile are unchanged. All required verification is complete.
Pattern checks currently construct a flag-free RegExp on every validation, and MinLength/MaxLength always open a code-point iterator even when UTF-16 bounds already decide the result. Reuse each static pattern lazily within its generated file and add constant-time acceptance bounds to the runtime length helpers, preserving code-point semantics and lazy invalid-pattern errors.
The native string checker recognizes the standard static pattern expression; custom validation code and flags retain their authored behavior. Generated cache slots are uninitialized var declarations so early calls through circular imports cannot encounter a temporal dead zone or have their cache reset. There is no new TypeScript API and no compiler-version upgrade is required.
Validation so far:
Includes scoped performance acknowledgments and the matching guide update. Package versions will be bumped only in the maintainer release step after merge.
Fixes #2504.