Skip to content

Bad performance #24

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

Open
pedro757 opened this issue May 6, 2025 · 0 comments
Open

Bad performance #24

pedro757 opened this issue May 6, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@pedro757
Copy link

pedro757 commented May 6, 2025

What version of Elysia is running?

What platform is your computer?

Linux 6.1.132-1-MANJARO x86_64 unknown

What steps can reproduce the bug?

import { faker } from "@faker-js/faker";
import { createAccelerator } from "json-accelerator";

import { Type as t } from "@sinclair/typebox";

function makeData(n) {
  const data = [];
  for (let i = 0; i < n; i++) {
    data.push({
      comprobanteId: faker.number.int({ min: 1000, max: 100000000 }),
      fechaComprobante: faker.string.alpha({ length: 10 }),
      fechaRef: faker.string.alpha({ length: 10 }),
      numeroComprobante: faker.string.ulid(),
      debe: faker.number.int({ min: 1000, max: 100000000 }),
      haber: faker.number.int({ min: 1000, max: 100000000 }),
      saldo: faker.number.int({ min: 1000, max: 100000000 }),
    });
  }
  return data;
}

function perfCheck() {
  const data = makeData(1_000_000);
  const schema = t.Array(
    t.Object({
      comprobanteId: t.Number(),
      fechaComprobante: t.String(),
      fechaRef: t.String(),
      numeroComprobante: t.String(),
      debe: t.Number(),
      haber: t.Number(),
      saldo: t.Number(),
    }),
  );
  const encoder = createAccelerator(schema);

  console.time("json-accelerator");
  encoder(data);
  console.timeEnd("json-accelerator");

  console.time("JSON Stringify");
  JSON.stringify(data);
  console.timeEnd("JSON Stringify");
}

perfCheck();

Node.js' Results:

First try:
json-accelerator: 2.077s                                                                                                                 
JSON Stringify: 439.266ms
Second try:
json-accelerator: 2.733s                                                                                                                 
JSON Stringify: 435.163ms   

Bun's Results:

First try:
[635.82ms] json-accelerator                                                                                                              
[359.79ms] JSON Stringify                                                                                                                
Second try:
[657.12ms] json-accelerator                                                                                                              
[358.27ms] JSON Stringify 

What is the expected behavior?

I don't know if this library is supposed to run under a specific enviroment to notice real performance improvement, but I was using it and I don't see the numbers that you put in the README, performance is actually much worse than regular JSON.stringify() as you can see

is it a elisiajs specific library ?
was it thought to handle arrays with large amount of data ?

What do you see instead?

Node.js' Results:

First try:
json-accelerator: 2.077s                                                                                                                 
JSON Stringify: 439.266ms
Second try:
json-accelerator: 2.733s                                                                                                                 
JSON Stringify: 435.163ms   

Bun's Results:

First try:
[635.82ms] json-accelerator                                                                                                              
[359.79ms] JSON Stringify                                                                                                                
Second try:
[657.12ms] json-accelerator                                                                                                              
[358.27ms] JSON Stringify 

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

No response

@pedro757 pedro757 added the bug Something isn't working label May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant