Skip to content

Commit

Permalink
lib: remove unnecessary refreshHrtimeBuffer()
Browse files Browse the repository at this point in the history
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.

PR-URL: #51446
Refs: #48655
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Jithil P Ponnan <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
  • Loading branch information
joyeecheung authored Jan 14, 2024
1 parent 7496bc4 commit 94f824a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
23 changes: 7 additions & 16 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -425,5 +417,4 @@ module.exports = {
wrapProcessMethods,
hrtime,
hrtimeBigInt,
refreshHrtimeBuffer,
};
2 changes: 0 additions & 2 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 94f824a

Please sign in to comment.