Skip to content

Poor BigInt Performance in Bun compared to other runtimes #23166

@tshmieldev

Description

@tshmieldev

What version of Bun is running?

1.2.23, 1.3

What platform is your computer?

Darwin 23.3.0 arm64 arm

What steps can reproduce the bug?

Run this code in Bun, and a runtime like Deno / Node

// Program counting fib(n)
let prev = BigInt(0);
let curr = BigInt(1);

let n = Number(process.argv.length > 2 ? process.argv[2] : null);

if(isNaN(n)) { console.log("Provide a valid number"); process.exit(0); }
let start = Date.now();
for(let i = 0; i < n; ++i){
    let tmp = prev + curr;
    prev = curr;
    curr = tmp;
}
let end = Date.now();
console.log(end - start);

Bun consistently takes ~2x as much time (Tested for n=100k, n=1mil)

What is the expected behavior?

At least the same performance as other runtimes

What do you see instead?

Slow performance

Additional information

There was an almost identical issue reported a few years ago, I was told to make a new issue because Bun has changed a lot since then

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjscRelated to an issue in JavaScriptCoreperformanceAn issue with performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions