llrt icon indicating copy to clipboard operation
llrt copied to clipboard

process.hrtime.bigint() returns result inconsistent with node.js runtime

Open floydspace opened this issue 1 year ago • 2 comments

// teat.js
console.log(process.hrtime.bigint());
image

https://github.com/awslabs/llrt/blob/b01b7aab8a8182b05be57cfa297235250e58817f/src/process.rs#L40

floydspace avatar Feb 13 '24 21:02 floydspace

Resolution should be the same, right now is micros rather than nanos. So we'll need to fix it!

richarddavison avatar Feb 13 '24 22:02 richarddavison

As a workaround I force convert to BigInt

diff --git a/src/internal/clock.ts b/src/internal/clock.ts
index 1277d2cd1b0454847bcb611ce22cd9beb3907398..eab666dfa2e5f1dfbcfbf405bc39e66d03cf7aaf 100644
--- a/src/internal/clock.ts
+++ b/src/internal/clock.ts
@@ -61,8 +61,8 @@ const processOrPerformanceNow = (function() {
   if (!processHrtime) {
     return performanceNowNanos
   }
-  const origin = performanceNowNanos() - processHrtime.bigint()
-  return () => origin + processHrtime.bigint()
+  const origin = performanceNowNanos() - BigInt(processHrtime.bigint())
+  return () => origin + BigInt(processHrtime.bigint())
 })()
 
 /** @internal */

floydspace avatar Feb 13 '24 22:02 floydspace