microsoft / microsoft/tslib

__spread Performance Issues

Open
#125 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

__spread

var tslib = require("tslib");
const { concat } = require('lodash')

var testPushES6 = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    const arr = arr1.push(...arr2)
}

var testPush = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    Array.prototype.push.apply(arr1, arr2)
}

var testPush2 = function(flag) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    arr1.push.apply(arr1, tslib.__spread(arr2));
}

var testConcat = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    var arr  = arr1.concat(arr2)
  }

var testConcat = function(abc) {
    var arr1 = [1,2,3,-1]
    var arr2 = [4,5,6,7,8,9,10,12,13,14,15,16,17,18,29,30,31,32,33,34,35,36,37,38,39,40]
    var arr  = concat(arr1, arr2)
  }

var count = 1000000

var date = Date.now()
for (var i = 0; i < count; i++) {
  testPushES6()
}
// 136
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testPush()
}
// 139
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testPush2()
}
// 1005
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testConcat()
}
// 310
console.log(Date.now() - date)

var date = Date.now()
for (var i = 0; i < count; i++) {
  testConcat2()
}
// 810
console.log(Date.now() - date)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the benchmark in the issue and inspect the tslib.__spread helper it exercises. Compare its results and timing with the native spread, Array.prototype.push.apply, and concat cases shown; done would require an agreed performance improvement without changing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.