Skip to content

Data: Feature detect and use Symbol if present #2676

@dcherman

Description

@dcherman

JSPerf: http://jsperf.com/defineproperty-vs-symbol-for-privacy

I've noticed that in much of my code, Data.key is often near the top of CPU time for initialization when hundreds or thousands of elements have their data initialized (as is sometimes the case using ngAnimate in Angular).

By feature detecting the presence of Symbol and using it rather than a non-enumerable property, this function went from like 70-100ms CPU time to 0.3 since not only does it not have the overhead of define property, but we can avoid the try/catch in that codepath as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions