tc39 / proposal-array-unique

ECMAScript proposal for Deduplicating method of Array
138 stars 7 forks source link

Implementation recommendations #14

Open dead-claudia opened 4 years ago

dead-claudia commented 4 years ago

This is more an FYI than a specific feature request. For ideal performance, implementations should consider the following:

TechQuery commented 4 years ago
  • For polyfills, using the obvious Array.from(set) rather than a parallel array.

"a parallel array" means [...new Set([])] ?

dead-claudia commented 4 years ago

I was referring to converting the set into an array at the end rather than building an array alongside the set.

hax commented 4 years ago

@isiahmeadows Not sure whether they would have perf difference...

dead-claudia commented 4 years ago

It may, considering CPU pipelines and such - with a specialized data structure, it becomes effectively just a copy, and CPUs like that. They can also allocate only the memory needed for the returned result in one single step as opposed to potentially multiple allocations in the loop, thus wasting less memory and reducing the overhead in the loop itself.

hax commented 4 years ago

It may also slower, especially in embed js engines. :-P

dead-claudia commented 4 years ago

Part of why I said "should consider" and not that it's an outright recommendation like using hash tables for Map - I know embedded and server engines don't work the same way and have two different sets of needs, and space constraints may very well preclude using those recommendations. (For BigInts, there's been some recent chatter in v8-dev of potentially creating a split implementation for multiplication and division of large BigInts to cater to both embedded and high-performance needs, and factoring it out into a standalone library for other runtimes to use. So there's precedent.)