Skip to content

refactor: Refactor mergeConfig function to remove duplicate keys - #5605

Closed
lei-mu wants to merge 2 commits into
axios:v1.xfrom
lei-mu:v1.x
Closed

lei-mu wants to merge 2 commits into
axios:v1.xfrom
lei-mu:v1.x

Conversation

@lei-mu

@lei-mu lei-mu commented Mar 16, 2023

Copy link
Copy Markdown

Refactor mergeConfig function to use uniqueArray for deduplication
This commit refactors the mergeConfig function to use the uniqueArray
function instead of an array concatenation and filtering method. This change
improves performance by reducing unnecessary iterations over large arrays, and
also simplifies the code. The resulting code is more efficient, easier to read,
and conforms better to modern JS standards.

@WillianAgostini

Copy link
Copy Markdown
Contributor

Hi @lei-mu
Great PR, I liked that with this change it was better to read the code.
I understood that the main point here is the increase in performance. Can you write a test case measuring this performance increase?

@DigitalBrainJS

Copy link
Copy Markdown
Collaborator

It is likely that a simple expression like

  utils.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
    //...
  });

will have better performance in a shorter form.

v16.19.0
unique performance:
spread x 366,729 ops/sec ±3.45% (74 runs sampled)
assign x 2,321,281 ops/sec ±2.62% (81 runs sampled)
filter x 1,572,643 ops/sec ±0.52% (90 runs sampled)
Fastest is assign

Process finished with exit code 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants