Javascript array performance

I checked every question and article about it that I could find, but actually nothing answers. I do it as if I have only one question, there are more of them.

Perhaps I should first explain what I'm trying to do, I create the File Manager completely in JavaScript, the File Manager receives the files from the Backend (PHP, Twig), and then saves them in the Folder array, each folder has its own Files, Folders is an array, and the files in each folder are also an array, these files are also displayed on the page, and the user can select, copy, cut, paste (other operations) them (I'm still writing down these operations because there is a problem here).
The files on the page have a data identifier assigned to them, so I can easily work with them between File Manager and Backend, and because I know the identifier of each and every file, I think that I could completely eliminate the intersection of file arrays in search of a specific file if I could only create an array that would take the file identifier as an index, but because it's JavaScript, I can do it! but there are some problems with it.

Trying to use an object for this task simply does not work, because it is simply slower than Array (now, I understand, the differences in speed, even if in millions, are not so big, but why not try digging for maximum performance, right? ?)

So, here is a list of questions I cannot find a reliable answer to:

  • Why is an object in Chrome much faster than an object in Firefox?
  • Why is access to the undefined index in Chrome so much slower?
  • Why is Firefox running much faster in Firefox than in Chrome?
  • I know why Chrome loses performance with higher indices (it converts an array to a list of 100 thousand, I think it was answered by a link to a source in another question about SO), but Firefox loses performance gradually, as if it went to higher indices sequentially, even if they are available directly, why?
  • Why is an array slow enough when it has only one element, but this element has a very high index?

There may be a few more questions, but I can't think about them right now.


, , , , , , , , , , 10, , .
http://jsperf.com/array-management-performance/2.

EDIT: , , "" jsperf minId maxId .


:

: Firefox 165.173 . / | Chrome 351,699 /
Undefined: Firefox 98.582 . / | Chrome 54,666 /
: Firefox 7.599 . / | Chrome 291.244 /
Write Far: Firefox 5.599 . / | Chrome 93,733 /
Write Overwrite: Firefox 7.599 / | Chrome 291.244 /

Read : Firefox 681.206 . / | Chrome 401,522 /
Undefined: Firefox 681.206 . / | Chrome 62,827 ​​/
: Firefox 400.234 . / | Chrome 121,519 /
: Firefox 348.560 . / | Chrome 121,519 /
Write Overwrite: Firefox 400.234 ops/sec | Chrome 234.337 ​​/

P.S. , Read Defined Chrome , Chrome ?

, , / , .

http://jsperf.com/array-management-performance/2
http://jsperf.com/array-in-the-middle-of-nowhere
http://jsperf.com/object-holey-performance-better
http://jsperf.com/object-performance-better
http://jsperf.com/array-vs-object-mine-v2/5

PS2 , Array Object, Object Test Array, , , , , , jsperf , .

P.S.3 , , , , , .

----------------------------------------------- ----------------------------

EDIT: (, , , )

() . , , , , , .

1, 2, 3, 4 5, : "- ", , , , , , , .

: , , , . JS, , , 100k JS. N JS /? ( , ).

: , , , , -, /-, , ( ).

, - ( , ) 10 , , O (1).

, JS- http://jsperf.com/array-of-arrays-with-high-indexes/2, , 1000 IS SUPER FAST ( ), , , 1D 3D, FastArray .

: http://jsperf.com/map-check-v2/5 - , , ... EDIT: , , , , , , jsperf - freaking, , .

https://github.com/ImJustAskingDude/JavascriptFastArray , .

P.S.4 . , , Ultimate Array Performance, . .

P.S.5 , , , , Chrome , , , .

+4
1

, JS- , .

, , JavaScript , , .

, Object "", undefined, JS , .

@RobG, , reduce, map forEach.

, Ramda Lodash, .

0

Source: https://habr.com/ru/post/1609873/


All Articles