From b21577c4da8c21191b19e6b2d5f54e143235ea2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Tue, 5 Sep 2023 21:25:20 -0300 Subject: [PATCH] perf(utils): increase max arguments & avoid shallow clone Co-authored-by: Alexandr Pestryakov --- packages/orama/src/methods/search.ts | 2 +- packages/orama/src/utils.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/orama/src/methods/search.ts b/packages/orama/src/methods/search.ts index d4237f9d6..e2e6f9a6c 100644 --- a/packages/orama/src/methods/search.ts +++ b/packages/orama/src/methods/search.ts @@ -28,7 +28,7 @@ import { InternalDocumentID, } from '../components/internal-document-id-store.js' import { createError } from '../errors.js' -import { getNanosecondsTime, getNested, sortTokenScorePredicate, safeAddNewItems, safeArrayPush } from '../utils.js'; +import { getNanosecondsTime, getNested, sortTokenScorePredicate, safeArrayPush } from '../utils.js'; const defaultBM25Params: BM25Params = { k: 1.2, diff --git a/packages/orama/src/utils.ts b/packages/orama/src/utils.ts index fdb6ff343..d1efac4fe 100644 --- a/packages/orama/src/utils.ts +++ b/packages/orama/src/utils.ts @@ -15,12 +15,12 @@ export const isServer = typeof window === 'undefined' * But i don't know if this value change from nodejs to nodejs * So I will keep a safer value here. */ -export const MAX_ARGUMENT_FOR_STACK = 10_000; +export const MAX_ARGUMENT_FOR_STACK = 65535; /** * This method is needed to used because of issues like: https://github.com/oramasearch/orama/issues/301 * that issue is caused because the array that is pushed is huge (>100k) - * + * * @example * ```ts * safeArrayPush(myArray, [1, 2]) @@ -28,10 +28,10 @@ export const MAX_ARGUMENT_FOR_STACK = 10_000; */ export function safeArrayPush(arr: T[], newArr: T[]): void { if (newArr.length < MAX_ARGUMENT_FOR_STACK) { - arr.push(...newArr) + Array.prototype.push.apply(arr, newArr) } else { for (let i = 0; i < newArr.length; i += MAX_ARGUMENT_FOR_STACK) { - arr.push(...newArr.slice(i, i + MAX_ARGUMENT_FOR_STACK)) + Array.prototype.push.apply(arr, newArr.slice(i, i + MAX_ARGUMENT_FOR_STACK)) } } }