Repository navigation
[NODEFS] Pass timestamps in seconds to utimes instead of Date instances - #27787
Merged
Merged
Conversation
Node's `fs.utimesSync`, `fs.lutimesSync`, and `fs.futimesSync` accept timestamps either as `Date` instances or as numbers in seconds. Passing seconds directly has multiple advantages: 1. Avoids allocating two temporary `Date` instances on each `setattr`. 2. Preserves sub-millisecond timestamp precision down to the host filesystem call rather than quantizing to integer milliseconds. 3. Aligns `NODEFS` with `NODERAWFS`, which already passes timestamps in seconds. 4. When preserving unspecified timestamps, reads `atimeMs` / `mtimeMs` instead of `atime` / `mtime` `Date` objects from `stat(arg)`. This may also help reduce flakiness in timestamp tests (such as `test_futimens`) when converting and checking sub-millisecond precision. See: emscripten-core#25280
sbc100
force-pushed
the
nodefs_utimes_seconds
branch
from
September 28, 2026 00:20
4813628 to
f76d1fc
Compare
guybedford
approved these changes
Sep 28, 2026
This was referenced Oct 6, 2026
sbc100
pushed a commit
that referenced
this pull request
Oct 6, 2026
`MEMFS.node_ops.getattr` returned the times only as `Date` objects, which hold whole milliseconds, so `stat()` truncated them even after `utimensat()` had stored a sub-millisecond value (#27794 keeps 10 µs). This also returns `atimeMs`/`mtimeMs`/`ctimeMs` with the exact values, as NODEFS does since #27787, and lets `SYSCALLS.writeStat` prefer the `*Ms` properties in every environment, not only when `ENVIRONMENT_MAY_BE_NODE` (MEMFS is used in the browser too). The `Date` properties stay, for JS users of `FS.stat`. The new test (`test_fs_subms_times`, all filesystems) sets a time with `utimensat()` and reads it back with `stat()` and `fstat()`; before this change only the MEMFS variant failed. Checked as well with `-sENVIRONMENT=web` in Chromium (`.123000000` before, `.123449951` after). Codesize: +54 bytes of JS where MEMFS is included; wasm unchanged. Not included: the second suggestion in the issue (stamping files with a sub-millisecond clock instead of `Date.now()`), which touches more places and changes behaviour; happy to do it as a follow-up if wanted. Fixes: #27885
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.
Node's
fs.utimesSync,fs.lutimesSync, andfs.futimesSyncaccept timestamps either asDateinstances or as numbers in seconds.Passing seconds directly has multiple advantages:
Dateinstances on eachsetattr.NODEFSwithNODERAWFS, which already passes timestamps in seconds.atimeMs/mtimeMsinstead ofatime/mtimeDateobjects fromstat(arg).This may also help reduce flakiness in timestamp tests (such as
test_futimens) when converting and checking sub-millisecond precision.See: #25280