Skip to content

Out of memory error when inintializing a merged type with a lot of or #1652

Done

Description

@floratmin

Report a bug

When I create a complex type, I get out-of-memory errors when initializing the type. This example also crashes the ArkType playground. I like this project very much, but unfortunately the initialization times are a real deal-breaker for using ArkType in Cloudflare Workers. Once initialized, the validation is super fast.

🔎 Search Terms

Out of memory
Memory leak

🧩 Context

  • ArkType version: 2.2.3
  • TypeScript version (5.1+): 5.9.3
  • Other context you think may be relevant (JS flavor, OS, etc.): Node 24.12.0

🧑‍💻 Repro

Playground Link: https://arktype.io/playground

    const Type1 = type({foo1: 'string', bar1: 'string'}).or({foo1: 'null', bar1: 'null'});
    const Type2 = type({foo2: 'string', bar2: 'string'}).or({foo2: 'null', bar2: 'null'});
    const Type3 = type({foo3: 'string', bar3: 'string'}).or({foo3: 'null', bar3: 'null'});
    const Type4 = type({foo4: 'string', bar4: 'string'}).or({foo4: 'null', bar4: 'null'});
    const Type5 = type({foo5: 'string', bar5: 'string'}).or({foo5: 'null', bar5: 'null'});
    const Type6 = type({foo6: 'string', bar6: 'string'}).or({foo6: 'null', bar6: 'null'});
    const Type7 = type({foo7: 'string', bar7: 'string'}).or({foo7: 'null', bar7: 'null'});
    const Type8 = type({foo8: 'string', bar8: 'string'}).or({foo8: 'null', bar8: 'null'});
    const Type9 = type({foo9: 'string', bar9: 'string'}).or({foo9: 'null', bar9: 'null'});
    const Type10 = type({foo10: 'string', bar10: 'string'}).or({foo10: 'null', bar10: 'null'});
    const Type11 = type({foo11: 'string', bar11: 'string'}).or({foo11: 'null', bar11: 'null'});
    const merged = Type1
      .merge(Type2)
      .merge(Type3)
      .merge(Type4)
      .merge(Type5)
      .merge(Type6)
      .merge(Type7)
      .merge(Type8)
      .merge(Type9)
      .merge(Type10)
      .merge(Type11);

Activity

  1. added
    bug
    on Aug 22, 2026
  2. pullfrog commented on Aug 22, 2026

    @pullfrog
    Contributor
  3. ssalbdivad commented on Dec 3, 2026

    @ssalbdivad
    Member

    fixed in arktype 3.0 (quadratic union reduction / discrimination fixes + lazy jit) — the 11-merge repro now initializes in ~110–160ms (~66mb heap) instead of ooming, and @ark/aot eliminates runtime init overhead on workers. (structurally, n chained .merge(a | b) calls still expand to 2^n dnf branches, so past ~11 nested pairs or a flat { foo1: "string | null", ... } with .narrow(...) keeps it o(n).) closing — reopen if you still hit anything on 3.0.1.

  4. moved this from To do to Done (merged or closed) in arktypeioon Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions