Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address misleading performance benchmarks #1303

Closed
ottomated opened this issue Feb 9, 2025 · 2 comments
Closed

Address misleading performance benchmarks #1303

ottomated opened this issue Feb 9, 2025 · 2 comments

Comments

@ottomated
Copy link

I was looking into migrating from Zod and was drawn by the validation benchmarks on both the homepage and blog post. My intuition, however, was that the expensive schema initialization step would make arktype a mistake for serverless environments such as Cloudflare workers where schemas are reinitialized on each request.

I verified it with a quick benchmark that shows a significant performance hit that unfortunately more than outweighs the gain on validation speed:

Image

import { run, bench, boxplot, summary } from 'mitata';
import { z } from 'zod';
import { type } from 'arktype';

boxplot(() => {
  summary(() => {
    bench('zod', () => z.object({
      string: z.string(),
      stringRange: z.string().min(0).max(10),
      optional: z.array(z.number()).optional(),
    }));
    bench('arktype', () => type({
      string: 'string',
      stringRange: '0 < string <= 10',
      'optional?': 'number[]',
    }));
  });
});

await run();

I understand that the library is not focused on initialization performance, but it feels a bit misleading to advertise a 100x speedup when a significant portion of your users will actually experience the opposite. Would it be possible to add a note mentioning this to the relevant docs pages?

@gregg-cbs
Copy link

I agree on this. One of the reasons we moved from zod was the performance benefits. Although this does not stray us from arktype, it solves some problems zod could not - like good union types. In mongodb this is essential.

Good post OP.

@ssalbdivad
Copy link
Member

ssalbdivad commented Feb 12, 2025

Yeah, it would be valuable to give a more nuanced breakdown of the tradeoffs here. I will try to do that in an upcoming comparisons section I have planned for the docs.

That said, I wouldn't say the existing framing is going out of its way to be misleading. It just references the only community-maintained validation benchmarks that exist. 100% agree it would be valuable for those to cover other scenarios like initialization or complex unions.

However, for environments sensitive to initialization speed/bundle size, there will be an opt-in build-step to avoid these costs in an upcoming release:

#810

For now, you may be interested in jitless mode. There will still be some overhead to intializing the fully-reduced types, but it would help mitigate it at the expense of validation speed.

@arktypeio arktypeio locked and limited conversation to collaborators Feb 12, 2025
@ssalbdivad ssalbdivad converted this issue into discussion #1309 Feb 12, 2025
@github-project-automation github-project-automation bot moved this from To do to Done (merged or closed) in arktypeio Feb 12, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
Status: Done (merged or closed)
Development

No branches or pull requests

3 participants