From b9e58f9c405e60af71d2926abc5bf1ba8348a8e6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 12 Jan 2024 23:03:16 +0100 Subject: [PATCH] lib: remove unnecessary refreshHrtimeBuffer() We now serialize/deseialize the hrtime buffers properly instead of throwing them away at serialization and creating new ones at pre-execution, so there is no need to reset the variables to the binding property at pre-execution time. --- lib/internal/process/per_thread.js | 23 +++++++---------------- lib/internal/process/pre_execution.js | 2 -- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 9b86f20053da3b..89428cf916aa29 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -57,21 +57,13 @@ const { exitCodes: { kNoFailure } } = internalBinding('errors'); const binding = internalBinding('process_methods'); -let hrValues; -let hrBigintValues; - -function refreshHrtimeBuffer() { - // The 3 entries filled in by the original process.hrtime contains - // the upper/lower 32 bits of the second part of the value, - // and the remaining nanoseconds of the value. - hrValues = binding.hrtimeBuffer; - // Use a BigUint64Array in the closure because this is actually a bit - // faster than simply returning a BigInt from C++ in V8 7.1. - hrBigintValues = new BigUint64Array(binding.hrtimeBuffer.buffer, 0, 1); -} - -// Create the buffers. -refreshHrtimeBuffer(); +// The 3 entries filled in by the original process.hrtime contains +// the upper/lower 32 bits of the second part of the value, +// and the remaining nanoseconds of the value. +const hrValues = binding.hrtimeBuffer; +// Use a BigUint64Array because this is actually a bit +// faster than simply returning a BigInt from C++ in V8 7.1. +const hrBigintValues = new BigUint64Array(binding.hrtimeBuffer.buffer, 0, 1); function hrtime(time) { binding.hrtime(); @@ -425,5 +417,4 @@ module.exports = { wrapProcessMethods, hrtime, hrtimeBigInt, - refreshHrtimeBuffer, }; diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index b6bdb4785003f7..98533b7828d3ff 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -211,8 +211,6 @@ function patchProcessObject(expandArgv1) { const binding = internalBinding('process_methods'); binding.patchProcessObject(process); - require('internal/process/per_thread').refreshHrtimeBuffer(); - // Since we replace process.argv[0] below, preserve the original value in case the user needs it. ObjectDefineProperty(process, 'argv0', { __proto__: null,