Skip to content

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions