bootstrap-table icon indicating copy to clipboard operation
bootstrap-table copied to clipboard

Use object.assign instead of extend

Open jimmywarting opened this issue 3 years ago • 4 comments

🤔Type of Request

  • [ ] Bug fix
  • [ ] New feature
  • [x] Improvement
  • [ ] Documentation
  • [ ] Other

🔗Resolves an issue?

  • part of #4796 #5526 (got to start out small)

📝Changelog

  • [ ] Core
  • [x] Extensions

💡Example(s)?

☑️Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • [ ] Doc is updated/provided or not needed
  • [ ] Demo is updated/provided or not needed
  • [ ] Changelog is provided or not needed

jimmywarting avatar Aug 21 '22 14:08 jimmywarting

I'm not sure if i'm a fan to use only assign instead of Object.assign. Does this have any advantages, because it's not that readable (especially for new devs in the project).

Also i'm not sure if we should replace $.extend with Object.assign or if we should write our own method for that (i think we need a custom function for deep copy either way). The extend function from jquery is faster then Object.assign if this benchmark is correct.

UtechtDustin avatar Aug 21 '22 17:08 UtechtDustin

Executed the test myself... it showed that spread was a clear winner in both safari and in chrome and that jQuery.extend was the slowest. chrome 104: https://www.measurethat.net/Benchmarks/ShowResult/326203 safari 15.6: https://www.measurethat.net/Benchmarks/ShowResult/326205

using const { assign } = Object instead of Object.assign makes it a tiny bit more friendlier for the other stuff to be GC, helps with code minification and also has a faster path lookup to increase perf b/c it's cached to a more closer local scope

anyhow this stuff didn't extend anything deeply so nothing like extend deep functionallity had to be written

the nice thing about using built in solution also is that stack traces gets shorter and easier to debug

jimmywarting avatar Aug 21 '22 17:08 jimmywarting

Firefox: https://www.measurethat.net/Benchmarks/ShowResult/326214

using const { assign } = Object instead of Object.assign makes it a tiny bit more friendlier for the other stuff to be GC, helps with code minification and also has a faster path lookup to increase perf b/c it's cached to a more closer local scope

I think our build script automatically optimize that, or not @wenzhixin ?

UtechtDustin avatar Aug 21 '22 18:08 UtechtDustin

I think our build script automatically optimize that.

Yes

wenzhixin avatar Aug 22 '22 00:08 wenzhixin

@wenzhixin @djhvscf your opinions about this ?

UtechtDustin avatar Oct 01 '22 12:10 UtechtDustin

I think we can modify the code in all src, not just this extension.

wenzhixin avatar Oct 08 '22 00:10 wenzhixin

@wenzhixin and what do you think about the benchmarks ?

UtechtDustin avatar Oct 08 '22 09:10 UtechtDustin

Updated in #6560

wenzhixin avatar Dec 17 '22 14:12 wenzhixin