From f727c5b90d4177c7999d93458c93796f985eaccd Mon Sep 17 00:00:00 2001 From: Dmytro Brahinets Date: Thu, 26 Jun 2025 19:59:49 +0300 Subject: [PATCH] Update 4-improved.js Provided an alternative point of view regarding the V8 optimisations. --- JavaScript/4-improved.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/JavaScript/4-improved.js b/JavaScript/4-improved.js index 20a016e..aa45b0f 100644 --- a/JavaScript/4-improved.js +++ b/JavaScript/4-improved.js @@ -1,7 +1,13 @@ 'use strict'; const poolify = (factory, { size, max }) => { - const instances = new Array(size).fill(null).map(factory); + // It seems that preallocated array with defined size + // and using c-like for-loop will be more efficient in terms of V8 optimisation than + // const instances = new Array(size).fill(null).map(factory); + const instances = new Array(size); + for(let i = 0; i < size; i++){ + instances[i] = factory(); + } const acquire = () => instances.pop() || factory(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy