Skip to content

Context-free traversal for determinstic morph at path #1380

Closed

Description

@ssalbdivad

Currently, tDelete is unnecessarily slow because it requires context despite its nested morph being deterministic.

We should be able to apply it optimistically with no allows context but my brain is too fried to fix it at the moment.

const tDelete = type
  .scope({}, { clone: false })
  .type({
    number: "number",
    negNumber: "number",
    maxNumber: "number",
    string: "string",
    longString: "string",
    boolean: "boolean",
    deeplyNested: {
      foo: "string",
      num: "number",
      bool: "boolean",
    },
  })
  .onDeepUndeclaredKey("delete");

bench("moltar delete", () => {
  tDelete(validData);
}).median([3.54, "us"]);

const tShallowDelete = type.scope({}, { clone: false }).type({
  "+": "delete",
  number: "number",
  negNumber: "number",
  maxNumber: "number",
  string: "string",
  longString: "string",
  boolean: "boolean",
});

bench("shallow delete", () => {
  tShallowDelete(validData);
}).median([370, "ns"]);

EDIT: Should also check if it can be improved further by inlining the specific missing keys?

EDIT2: Should see if the solution here also fixes #1375

Activity

  1. moved this from To do to Planned in arktypeioon Mar 24, 2025
  2. moved this from Planned to Backlog in arktypeioon Apr 3, 2025
  3. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    MemberAuthor

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions