GitShow/ljharb/safe-array-concat
ljharb

safe-array-concat

`Array.prototype.concat`, but made safe by ignoring Symbol.isConcatSpreadable

by ljharb
arrayconcatisconcatspreadable
Star on GitHubForknpm

JavaScript

5 stars2 forks2 contributorsQuiet · 2mo agoSince 2023MIT

Meet the team

See all 2 on GitHub →
ljharb
ljharb43 contributions
infinity-naveen
infinity-naveen1 contribution

Languages

View on GitHub →
JavaScript100%

Commit activity

Last 12 weeks · 4 commits

Full graph →

Recent fixes

View closed PRs →
gabrielogregorio
Que tal adicionar um .npmignore para ignorar alguns arquivos da biblioteca?ClosedIssue

Hello, I would like to propose adding a file to the project. This would allow publishing to npm to ignore files that are not essential for deployment to production environments, such as: These files are generally only used during development and are not needed in the final distribution of the library. Implementing this change would help reduce the library package size, thus optimizing efficiency for end users. I include a screenshot below to illustrate the location of the files mentioned in the current repository: !Captura de tela de 2023-11-28 08-27-23 Thank you for your attention and I am available to discuss this suggestion further.

gabrielogregorio · 2y ago
infinity-naveen
Performance issue due to Symbol.isConcatSpreadable setClosedIssue

Description We have been facing high CPU utilisation issues in our projects since April 2023. On debugging, we found that many dependencies were updated at that time (e.g. , , , etc.). And all of these started using package. On further deep-driving, we observed that loading of this package safe-array-concat is impacting performance of Array function by around 20x in our whole application, and since concat() operation is used at lot of places in our code, it caused significant increase on our server's CPU utilisation. Root Cause On analysing source code, we found culprit line of code: https://github.com/ljharb/safe-array-concat/blob/f929a1b65eb3525d93296ecc12f709b18089081c/index.js#L16C1-L17C1 Actually, this code is also not the root cause, here is used as per requirement. Actual root cause is the V8 Engine (which is powering NodeJs). As per it's current implementation, if we set to any array or object (even such single usage will trigger it), it will make all subsequent usages of Array.concat() slower in whole application. Reference: https://github.com/v8/v8/blob/bf4b542a1b31bbe8106e394b1dbeff02571dff4b/src/builtins/builtins-array.cc#L1542 Additional Context In our case in all projects, the only such usage of symbol (where we are setting it to any value/array) is in this package code. As soon as we require safe-array-concat in our app, above mentioned line is executed & all subsequent concat() operations' performance is impacted. Steps to Reproduce Issue Code: Execution results**: :: 2.5 sec :: 113 ms :: 6.3 sec :: 275 ms

infinity-naveen · 2y ago
infinity-naveen
[Perf] set `Symbol.isConcatSpreadable` only when required MergedPR

Context: Issue: https://github.com/ljharb/safe-array-concat/issues/2 Changes done in PR: Since, we were facing issue on setting on initialisation, we just move this statement inside safeArrayConcat function & execute only when we get any value on which this symbol was already set. Since, reference is passed in callBind.apply(), setting symbol key later after apply() should also make working of $concatApply as expected. Steps to verify: executed Existing 9 test cases were executed and all were passed. Below code snippet was also executed: Test execution results**:: :: 114 ms :: 113 ms :: 268 ms :: 275 ms (No impact of requiring package on our application now)

infinity-naveen · 2y ago
Structured data for AI agents

Repository: ljharb/safe-array-concat. Description: `Array.prototype.concat`, but made safe by ignoring Symbol.isConcatSpreadable Stars: 5, Forks: 2. Primary language: JavaScript. Languages: JavaScript (100%). License: MIT. Topics: array, concat, isconcatspreadable. Open PRs: 0, open issues: 1. Last activity: 2mo ago. Top contributors: ljharb, infinity-naveen.

·@ofershap

Replace github.com with gitshow.dev