Skip to content

Performance Issue: Object allocation via new is 100x slower than Node.js in PerryTS #945

@lanbomo

Description

@lanbomo

A user tested the code below and found that it suffers from poor performance, being 100 times slower than Node.js. If you have time, please investigate it. Preliminary analysis suggests it's caused by object instantiation using new. Could there be some time-consuming operations during the new process? Generally, people don't write code this way, but in Node.js, this kind of usage takes a normal amount of time, whereas in PerryTS, it is not normal. If you can investigate and fix this, it would be great.

hello.ts

class MyClass {
    private value: number;
    constructor(value: number) {
        this.value = value;
    }
    getValue() {
        return this.value;
    }
}

function main() {
    const iterations = 100000000;

    // 类实例化和调用
    let start = performance.now();
    let sum = 0;
    for (let i = 0; i < iterations; i++) {
        const obj = new MyClass(1);
        sum += obj.getValue();
    }
    let end = performance.now();
    let elapsed = end - start;
    console.log(`${elapsed} ms, sum: ${sum}`);

    // 纯计算测试
    start = performance.now();
    sum = 0;
    for (let i = 0; i < iterations; i++) {
        sum += 1;
    }
    end = performance.now();
    elapsed = end - start;
    console.log(`${elapsed} ms, sum: ${sum}`);
}

main();

Machine System: Windows 10

Nodejs:v24.15.0, result:
node hello.ts
153.82350000000002 ms, sum: 100000000
122.30950000000001 ms, sum: 100000000

PerryTS:v0.5.923, result:
.\hello.exe
16970.964111328125 ms, sum: 100000000
143.921142578125 ms, sum: 100000000

A net friend tested with cpp:

Image

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