improve precision of @env.now() on native backend#3405
Merged
Conversation
Collaborator
Pull Request Test Coverage Report for Build 3717Details
💛 - Coveralls |
bobzhang
approved these changes
Apr 2, 2026
Contributor
bobzhang
left a comment
There was a problem hiding this comment.
[AI Rally - Reviewer]
Clean, well-motivated change that improves @env.now() precision on the native backend from second-level to millisecond-level. The old implementation called C's time() (second precision) and multiplied by 1000, which meant sub-second time differences were lost. The new implementation directly calls moonbit_get_ms_since_epoch from the updated native runtime, which provides true millisecond precision. The change reduces 7 lines to 1, maintains the same now_internal() -> UInt64 signature so callers are unaffected, and the dependency on the new runtime API is documented in the PR description with a link to the runtime commit.
dea6aca to
55a96d3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The API
@env.now()should return the duration of time since the Unix epoch in milliseconds. However, previously its implementation on native backend only has second precision. With moonbitlang/moonbit-native-runtime@eac2ffc, the latest MoonBit native runtime now provides an API for getting millisecond precision time. This PR utilizes the new runtime API to fix the precision of@env.now().