Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
4 votes
2 answers
120 views

Why is pre-allocation of arrays slower than dynamic pushing in JavaScript?

I have been testing two methods of array creation and initialization in JavaScript using Node.js. One method involves dynamically pushing elements into the array, while the other method involves pre-...
Mikhael Abdallah's user avatar
1 vote
1 answer
219 views

In V8 JS, do packed arrays of objects (PACKED_ELEMENTS) reserve consecutive system memory if all elements are the same hidden class?

For example: const array = []; for(let i = 0; i<20000; i++) array.push({x:1.2, y:3.4, t:123+i}); The hidden class of each element would be: [double, double, small integer]. Are the contents ...
2bam's user avatar
  • 119
1 vote
1 answer
117 views

JavaScript Objects and Sorted Integer Keys under the hood

I have searched a bunch of other resources but have not been able to find a quality answer to this question. JavaScript objects sort their integer keys in ascending order, not insertion order. const ...
Andrew Lovato's user avatar
1 vote
2 answers
289 views

V8 engine: why object spread at the start of new object create new hidden classes only after ninth element? Otherwise if spread at the end - its ok

I just read about hidden classes and inline caching. I found interesting performance thing, that break my mind. So, we have the following code: const n = 100000; const array = []; for (let i = 0; i &...
Alexander Garkavenko's user avatar
17 votes
1 answer
1k views

JavaScript array performance drop at 13k-16k elements

I am doing some performance testing regarding creating and editing performance of arrays and noticed that there are some weird characteristics around arrays with about 13k-16k elements. The below ...
Teiem's user avatar
  • 1,559
0 votes
0 answers
421 views

Use spread operator over a spread operator on an 2-d array [duplicate]

Is there a way to use a spread operator over another spread operator? const arr = [[1,2,3],[4],[5,6],[7,8,9]]; const spreadArr = [...arr]; // This works console.log(spreadArr); // [[1,2,3],[4],[5,6],[...
Trishant Pahwa's user avatar
0 votes
1 answer
124 views

How to introspect elements kind in an array in V8

After reading this article: https://v8.dev/blog/elements-kinds. I was wondering if some of the arrays that are created in my code are packed or holey. Is there any way to check this at runtime in a ...
CÇ.'s user avatar
  • 243
10 votes
1 answer
12k views

Time complexity of Javascript Array.find() in modern browsers

Since array.find() iterates over an array, if I handle (potentially) large arrays, I always make sure to have an indexed object like so: { [id:string]: Item } if I need to look up items by id in ...
Sventies's user avatar
  • 2,634
0 votes
0 answers
45 views

Any way to force js engines to unroll a loop? [duplicate]

I have a performance critical queue container that does a lot of random inserts/deletes. In my container class, I have a fixed size Uint32Array called updates and in my insert logic, I need to compare ...
user81993's user avatar
  • 6,485
3 votes
1 answer
336 views

Is an array of ints actually implemented as an array of ints in JavaScript / V8?

There is claim in this article that an array of ints in JavaScript is implemented by a C++ array of ints. However; According to MDN unless you specifically use BigInts, in JavaScript all numbers are ...
user17331023's user avatar
1 vote
3 answers
223 views

Extract subarray of Columns from a multidimensional array and mutate the original array to remove those columns JavaScript

I want to extract a subarray of Columns from a multidimensional array and mutate the original array to remove those columns in JavaScript Ex: If I have an array originalArray = [ [A, B, C, D, E, F], ...
xyz333's user avatar
  • 758
0 votes
1 answer
388 views

Nodejs c++ addon: Not able to access Array elements

I want to access the elements of an array that is passed in a function as an arg from the js side. The code is like this: void Method(const FunctionCallbackInfo<Value> &args){ Isolate* ...
Sudesh Chaudhary's user avatar
1 vote
0 answers
18 views

Storing shuffled arrays in a parrent array [duplicate]

Problem : Main array have identical arrays instead of shuffle arrays after shuffling // Initiating an empty array const mainArr = [] // Random array with any values const arr = [1, 2, 3, 4, 5] /...
user11917406's user avatar
5 votes
1 answer
3k views

Object.entries() time complexity

Does anyone know the complexity of Object.entries() in Javascript? Based on this question I'd guess at maybe O(n) as well if it's implemented by obtaining the keys and values as arrays then zipping ...
James Paterson's user avatar
2 votes
2 answers
725 views

Why is if(1) faster than if(true)

I'm trying to make Conway's game of life in JavaScript and canvas, I have a matrix of 1280x720 that I use to store cells data, I'm currently storing the data as 1 = alive, 0 = dead, and then when I ...
Specy's user avatar
  • 331

15 30 50 per page
1
2 3 4 5