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

Use musl's strptime implementation #22158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 28, 2024

This is a slight regression in code size compared the JS version, but makes
the wasm file more standalone and portable. I measured the combined size of
core2.test_strptime_days (with closure compiler enabled) and got the
following results, which is a 2% regression:

  • before: 16777 bytes
  • after: 17235 bytes

As part of this I updated musl's implementation to support several
features that our current tests depend on:

  • Add support for '%z' for parsing timezone offsets.
  • Add support for '%U' and '%W' (week of the year)
  • Derive and set tm_yday/tm_mday/tm_yday fields where possible.

Regarding '%U' and '%W' it seems this is missing from both musl and
bionic:

However, I implemented here (based on code from FreeBSD) in order to
avoid any regressions (since we do have test coverage for these flags).

Fixes: #21024

@sbc100 sbc100 changed the title Musl strptime Use musl's strptime implementation Jul 2, 2024
@sbc100 sbc100 force-pushed the musl_strptime branch 5 times, most recently from 0140332 to 6d57da2 Compare July 3, 2024 18:26
@sbc100 sbc100 requested review from kripken and dschuff July 3, 2024 18:27
@sbc100 sbc100 force-pushed the musl_strptime branch 3 times, most recently from 8cce466 to 5649b70 Compare July 3, 2024 18:47
@kripken
Copy link
Member

kripken commented Jul 3, 2024

This seems to save on code size compared the JS version [..] I measured the combined size of core2.test_strptime_days (with closure compiler enabled) and got the following results:

before: 16777 bytes
after: 17235 bytes

That looks like a regression, not a savings, or are the two sentences talking about different things?

@sbc100
Copy link
Collaborator Author

sbc100 commented Jul 3, 2024

This seems to save on code size compared the JS version [..] I measured the combined size of core2.test_strptime_days (with closure compiler enabled) and got the following results:
before: 16777 bytes
after: 17235 bytes

That looks like a regression, not a savings, or are the two sentences talking about different things?

Yeah sorry, it was a saving, but then once I added all that new code (the stuff that musl doesn't implement) it grew by a little and now its a slight regression., but its only 2%.

This is a slight regression in code size compared the JS version, but
makes the wasm file more standalone and portable.   I measured the
combined size of `core2.test_strptime_days` (with closure compiler
enabled) and got the following results, which is a 2% regression:

- before: 16777 bytes
- after: 17235 bytes

As part of this I updated musl's implementation to support several
features that out current tests depend on:

- Add support for '%z' for parsing timezone offsets.
- Add support for '%U' and '%W' (week of the year)
- Derive and set tm_yday/tm_mday/tm_yday fields where possible.

Regarding '%U' and '%W' it seems this is missing from both musl and
bionic:

- https://github.com/aosp-mirror/platform_bionic/blob/4cfb2bde90fcf0a1f835e2b670b00e9f226c1c7c/libc/tzcode/strptime.c#L364-L375
- https://github.com/bminor/musl/blob/f314e133929b6379eccc632bef32eaebb66a7335/src/time/strptime.c#L126-L132

However, I implemented here (based on code from FreeBSD) in order to
avoid any regressions (since we do have test coverage for these flags).

Fixes: emscripten-core#21024
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
Copy link
Member

Choose a reason for hiding this comment

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

These licenses look like 2-part BSD, which is different from musl and Emscripten's MIT license. We'd need to mention that in our main LICENSE file (which so far has only had to talk about MIT).

This isn't a big deal, I think, but given this also increases code size I am a little unsure of the benefit here. The code being more standalone is helpful, but maybe there are other ways to achieve that?

(Does WASI not have APIs to get the day of the week and stuff like that, like the Web does? If it does then perhaps we can farm out to Web/WASI APIs rather than bundle this code.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another option is to remove all these additions, which would:

(1) + remove the license stuff
(2) + make this change a code size win
(3) - regress out support for certain formatting chars (to the same level as musl).

Regarding WASI APIs, no I don't think that would be needed since there is nothing system dependent going on here, we are just translating data from one format to another.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Regarding the license, yes that is annoying I forgot we don't already have BSD stuff in out stdlib..

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.

Behavioral inconsistency of strptime between emscripten and glibc/musl
2 participants