Skip to content

Performance: Cast.toString should not call String if it's already string #2571

Open
@apple502j

Description

@apple502j

for util/cast.js

    static toString (value) {
        return typeof value === 'string' ? value : String(value);
    }

is approx. 7x faster. This function is called in many places, so it's good to boost performance a bit.

Cast.toString 100 * 1000000
average:         10.880438989773392
min:     9.057298995554447
max:     22.80450100451708
OldCast.toString 100 * 1000000
average:         74.98821302987635
min:     68.54039999842644
max:     187.1899999976158

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions