Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move more time functions to native code. NFC #16439

Merged
merged 1 commit into from
Mar 9, 2022
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 7, 2022

I'm pretty this is going to be codesize win for a lot of
codebases even though its not showing up in our (minimal)
codesize tests.

Inspired by #16401

@sbc100 sbc100 force-pushed the time_library_funcs branch from 071e9be to d755dfe Compare March 7, 2022 19:56
@sbc100 sbc100 requested review from kripken and kleisauke March 7, 2022 20:06
@sbc100 sbc100 force-pushed the time_library_funcs branch 2 times, most recently from f6098a6 to cc94147 Compare March 7, 2022 21:55
@sbc100 sbc100 changed the base branch from main to exportRuntime March 8, 2022 00:37
sbc100 added a commit that referenced this pull request Mar 8, 2022
…unction. NFC

This test was under `core` instead of `other`.

Avoiding the use of `clock_gettime` since I'm about move that
to natice code with #16439.
sbc100 added a commit that referenced this pull request Mar 8, 2022
…unction. NFC (#16442)

This test was under `core` instead of `other`.

Avoiding the use of `clock_gettime` since I'm about move that
to native code with #16439.
@sbc100 sbc100 force-pushed the time_library_funcs branch from cc94147 to 01febf8 Compare March 8, 2022 01:52
Base automatically changed from exportRuntime to main March 8, 2022 02:39
@sbc100 sbc100 force-pushed the time_library_funcs branch from 01febf8 to e29e125 Compare March 8, 2022 02:39
@sbc100 sbc100 force-pushed the time_library_funcs branch from e29e125 to 61b3005 Compare March 8, 2022 05:31
@sbc100 sbc100 requested a review from tlively March 9, 2022 07:04
Copy link
Collaborator

@kleisauke kleisauke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left a possible further improvement as inline comment.

@@ -2463,8 +2382,9 @@ LibraryManager.library = {

// Represents whether emscripten_get_now is guaranteed monotonic; the Date.now
// implementation is not :(
$nowIsMonotonic__internal: true,
#if MIN_IE_VERSION <= 9 || MIN_FIREFOX_VERSION <= 14 || MIN_CHROME_VERSION <= 23 || MIN_SAFARI_VERSION <= 80400 // https://caniuse.com/#feat=high-resolution-time
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional directive is duplicated three times in this file. As an possible follow-up, perhaps we could make a performance.now() polyfill in src/polyfill that calls Date.now() - nowOffset if unsupported (e.g. https://gist.github.com/paulirish/5438650)? Then we could just call that polyfill throughout this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Feel free to propose a PR.. or open a bug to refactor that.

I'm pretty this is going to be codesize win for a lot of
codebases even though its not showing up in our (minimal)
codesize tests.
@sbc100 sbc100 force-pushed the time_library_funcs branch from 61b3005 to 6229f01 Compare March 9, 2022 15:54
@sbc100 sbc100 enabled auto-merge (squash) March 9, 2022 15:54
@sbc100 sbc100 merged commit fa6afb8 into main Mar 9, 2022
@sbc100 sbc100 deleted the time_library_funcs branch March 9, 2022 18:21
sbc100 added a commit that referenced this pull request Jul 8, 2022
This brings us back in line with upstream musl.  The change to 32-bit
was only recently made in #16966. The reason we made this change was
made was because we had certain C library calls that were implemented in
JS that returned `time_t`.  Since returning 64-bit values from JS
functions is not always easy (we don't always have WASM_BIGINT
available) that simplest solution was to define `time_t` to 32-bit which
doesn't have issues at the JS boundary.

However, in the intervening time many of the `time_t`-returning function
have been moved into native code (See #16606 and #16439) with only two
remaining: _mktime_js and _timegm_js.  So this change redefines just
those two functions to return `int` while keeping `time_t` itself as
64-bit.

Fixes: #17393
@sbc100 sbc100 mentioned this pull request Jul 8, 2022
sbc100 added a commit that referenced this pull request Jul 8, 2022
This brings us back in line with upstream musl.  The change to 32-bit
was only recently made in #16966. The reason we made this change was
made was because we had certain C library calls that were implemented in
JS that returned `time_t`.  Since returning 64-bit values from JS
functions is not always easy (we don't always have WASM_BIGINT
available) that simplest solution was to define `time_t` to 32-bit which
doesn't have issues at the JS boundary.

However, in the intervening time many of the `time_t`-returning function
have been moved into native code (See #16606 and #16439) with only two
remaining: _mktime_js and _timegm_js.  So this change redefines just
those two functions to return `int` while keeping `time_t` itself as
64-bit.

Fixes: #17393
sbc100 added a commit that referenced this pull request Jul 8, 2022
This brings us back in line with upstream musl.  The change to 32-bit
was only recently made in #16966. The reason we made this change was
made was because we had certain C library calls that were implemented in
JS that returned `time_t`.  Since returning 64-bit values from JS
functions is not always easy (we don't always have WASM_BIGINT
available) that simplest solution was to define `time_t` to 32-bit which
doesn't have issues at the JS boundary.

However, in the intervening time many of the `time_t`-returning function
have been moved into native code (See #16606 and #16439) with only two
remaining: _mktime_js and _timegm_js.  So this change redefines just
those two functions to return `int` while keeping `time_t` itself as
64-bit.

Fixes: #17393
sbc100 added a commit that referenced this pull request Jul 8, 2022
This brings us back in line with upstream musl.  The change to 32-bit
was only recently made in #16966. The reason we made this change was
made was because we had certain C library calls that were implemented in
JS that returned `time_t`.  Since returning 64-bit values from JS
functions is not always easy (we don't always have WASM_BIGINT
available) that simplest solution was to define `time_t` to 32-bit which
doesn't have issues at the JS boundary.

However, in the intervening time many of the `time_t`-returning function
have been moved into native code (See #16606 and #16439) with only two
remaining: _mktime_js and _timegm_js.  So this change redefines just
those two functions to return `int` while keeping `time_t` itself as
64-bit.

Fixes: #17393
sbc100 added a commit that referenced this pull request Jul 8, 2022
This brings us back in line with upstream musl.  The change to 32-bit
was only recently made in #16966. The reason we made this change was
made was because we had certain C library calls that were implemented in
JS that returned `time_t`.  Since returning 64-bit values from JS
functions is not always easy (we don't always have WASM_BIGINT
available) that simplest solution was to define `time_t` to 32-bit which
doesn't have issues at the JS boundary.

However, in the intervening time many of the `time_t`-returning function
have been moved into native code (See #16606 and #16439) with only two
remaining: _mktime_js and _timegm_js.  So this change redefines just
those two functions to return `int` while keeping `time_t` itself as
64-bit.

Fixes: #17393
xbcnn pushed a commit to xbcnn/emscripten that referenced this pull request Jul 22, 2022
This brings us back in line with upstream musl.  The change to 32-bit
was only recently made in emscripten-core#16966. The reason we made this change was
made was because we had certain C library calls that were implemented in
JS that returned `time_t`.  Since returning 64-bit values from JS
functions is not always easy (we don't always have WASM_BIGINT
available) that simplest solution was to define `time_t` to 32-bit which
doesn't have issues at the JS boundary.

However, in the intervening time many of the `time_t`-returning function
have been moved into native code (See emscripten-core#16606 and emscripten-core#16439) with only two
remaining: _mktime_js and _timegm_js.  So this change redefines just
those two functions to return `int` while keeping `time_t` itself as
64-bit.

Fixes: emscripten-core#17393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants