1. 31

  2. 6

    So what we’re saying, if anything sets Symbol.IsConcatSpreadable anywhere in the gazillion deps of your average NodeJS-application, the speed of Array.concat for the entire javascript engine will suffer?

    Hm Hm can I implement a runtime check for this?

    1. 2

      If you’re running on known hardware it’d be pretty easy to test for the performance regression…

      1. 2

        Maybe run a benchmark to get a baseline, turn IsConcatSpreadable on, run the benchmark again, compare the times, and if there’s no significant change IsConcatSpreadable was already turned on?

      2. 2

        MDN says

        The Symbol.isConcatSpreadable well-known symbol is used to configure if an object should be flattened to its array elements when using the Array.prototype.concat() method.

        I was like: “‘well-known’? I’ve never heard of this”. Then I went to the spec

        Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification

        So, uhh, not probably most people’s definition of “well-known”, but it didn’t answer my real question: why does this exist? Who needs this? It just seems like a good source of surprising behaviour. Has anyone here ever had cause to use this symbol?

        1. 2

          If I had to guess, it’s probably an obscure part of the spec that was implemented in V8 just for completeness and the reason why it’s implemented so sloppily is exactly because it’s not well known in the literal sense. Maybe other JS engines implement it per-object rather than globally.

          1. 1

            FWIW “well-known” has a technical meaning in a few other places (e.g. “well-known” URLs are a subset of URLs that have certain implications if present, as used in domain validation for example) so it isn’t like the spec made that definition up.