Page MenuHomeFeedback Tracker

[Suggestion] Change the +Array (array copy) operator to make it faster
Closed, ResolvedPublic

Description

I'm not sure what kind of operation you use for array copy +Array command, but it's kind of slow.

I recommend that you change it so that it just sums the array with an empty array, i.e.:

Array + []

Which can be significantly faster when copying large arrays, while maintaining the same speed for small arrays (see below).

For arrays with fewer than 11 elements, the +Array command is slightly faster (less than 0.00005 ms); at 11 elements, they both perform the same, and the difference keeps growing with the number of elements. For nested arrays, total number of elements (i.e. variable size) is the defining parameter.

Details

Severity
Minor
Resolution
Won't Fix
Reproducibility
Always
Operating System
Windows 7
Category
Scripting
Steps To Reproduce

Run this in the debug console.

_a=[];
for "_i" from 0 to 1000 do {
_a pushBack _i
};

[diag_codePerformance [{_this+[]},_a] select 0, 
diag_codePerformance [{+_this},_a] select 0]

The suggested method is over 50% faster for an array with 1000 elements.
For an array with 10000 elements, it's 300% faster!

Event Timeline

Leopard20 created this task.Aug 5 2020, 8:14 PM
Leopard20 edited Steps To Reproduce. (Show Details)
Leopard20 edited Steps To Reproduce. (Show Details)
Leopard20 renamed this task from [Suggestion] Change the +Array (array copy) to make it faster to [Suggestion] Change the +Array (array copy) operator to make it faster.Aug 5 2020, 8:18 PM
Leopard20 edited Steps To Reproduce. (Show Details)
Leopard20 updated the task description. (Show Details)Aug 5 2020, 8:29 PM
Leopard20 updated the task description. (Show Details)
Leopard20 updated the task description. (Show Details)Aug 5 2020, 8:32 PM
h- added a subscriber: h-.Aug 6 2020, 8:49 AM

array + [] and +array are not the same and cannot be improved in the way you suggest. added warning here: https://community.bistudio.com/wiki/%2B

BIS_fnc_KK closed this task as Resolved.Aug 6 2020, 10:04 AM
BIS_fnc_KK changed Resolution from Open to Won't Fix.

Hmm. I didn't notice that (although it doesn't cause any problems for my use). Thanks for the tip.