Skip to content

Bad performance #24

Open
Open
@pedro757

Description

@pedro757

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions