Skip to content
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

Make discriminated unions significantly faster #3

Open
vbudovski opened this issue Jul 16, 2024 · 0 comments
Open

Make discriminated unions significantly faster #3

vbudovski opened this issue Jul 16, 2024 · 0 comments

Comments

@vbudovski
Copy link
Owner

There needs to be some special handling for validating discriminated unions specifically, as the benchmarks below show. Regular unions do not exhibit this drastic drop on performance when matching a second or subsequent member.

benchmark                time (avg)        iter/s             (min … max)       p75       p99      p995
------------------------------------------------------------------------- -----------------------------

group Discriminated union 1
Paseri                   55.36 ns/iter  18,064,676.7   (48.2 ns … 129.57 ns) 55.74 ns 87.17 ns 98.02 ns
Zod (regular)           403.06 ns/iter   2,481,003.8   (341.05 ns … 1.18 µs) 408.11 ns 635.94 ns 1.18 µs
Zod (discriminator)     401.87 ns/iter   2,488,366.0 (347.92 ns … 645.58 ns) 409.87 ns 608.34 ns 645.58 ns
Valita                   59.23 ns/iter  16,882,259.3  (51.65 ns … 149.89 ns) 59.24 ns 90.23 ns 97.28 ns

summary
  Paseri
   1.07x faster than Valita
   7.26x faster than Zod (discriminator)
   7.28x faster than Zod (regular)

group Discriminated union 2
Paseri                  257.47 ns/iter   3,883,929.6  (224.5 ns … 406.37 ns) 265.96 ns 339.28 ns 364.05 ns
Zod (regular)             1.89 µs/iter     530,222.7     (1.46 µs … 3.02 ms) 1.75 µs 5.17 µs 9.43 µs
Zod (discriminator)     494.33 ns/iter   2,022,946.7  (441.49 ns … 695.7 ns) 503.44 ns 640.07 ns 695.7 ns
Valita                   76.52 ns/iter  13,067,883.5  (68.04 ns … 122.91 ns) 77.33 ns 108.37 ns 115.75 ns

summary
  Valita
   3.36x faster than Paseri
   6.46x faster than Zod (discriminator)
   24.65x faster than Zod (regular)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant