proposal-array-unique icon indicating copy to clipboard operation
proposal-array-unique copied to clipboard

Implementation recommendations

Open dead-claudia opened this issue 5 years ago • 6 comments

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

  • Using a specialized append-only set rather than the built-in ES one, as only "has" and "add" are ever used.
  • For integer arrays, using a sparse bit set rather than a traditional set to improve both speed and memory.
  • For polyfills, using the obvious Array.from(set) rather than a parallel array.

dead-claudia avatar Jul 28 '20 13:07 dead-claudia

  • For polyfills, using the obvious Array.from(set) rather than a parallel array.

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

TechQuery avatar Sep 10 '20 10:09 TechQuery

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

dead-claudia avatar Sep 10 '20 14:09 dead-claudia

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

hax avatar Sep 10 '20 16:09 hax

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.

dead-claudia avatar Sep 10 '20 16:09 dead-claudia

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

hax avatar Sep 10 '20 19:09 hax

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.)

dead-claudia avatar Sep 10 '20 21:09 dead-claudia