Skip to content

perf(syntax,codegen): Replace ryu_js with dragonbox_ecma for floating point formatting#12821

Merged
Boshen merged 2 commits intomainfrom
copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf
Aug 6, 2025
Merged

perf(syntax,codegen): Replace ryu_js with dragonbox_ecma for floating point formatting#12821
Boshen merged 2 commits intomainfrom
copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf

Conversation

Copy link
Contributor

Copilot AI commented Aug 5, 2025

This PR replaces the ryu_js crate with dragonbox_ecma for floating point to string conversion across the oxc codebase.

Motivation

The migration moves from ryu_js to dragonbox_ecma to modernize floating point formatting while maintaining ECMAScript specification compliance for JavaScript/TypeScript tooling.

Changes

Dependencies

  • Workspace: Updated from ryu-js = "1.0.2" to dragonbox_ecma = "0.0.3"
  • oxc_estree: Updated serialize feature dependency
  • oxc_syntax: Updated to_js_string feature dependency
  • oxc_codegen: Updated direct dependency

Implementation

  • oxc_estree: Replaced ryu_js::Buffer with dragonbox_ecma::Buffer for f64 formatting. Since dragonbox_ecma only supports f64, implemented custom f32 formatting for edge cases (MIN/MAX values) to maintain exact compatibility with existing tests.
  • oxc_syntax: Updated ToJsString trait implementation to use dragonbox_ecma::Buffer
  • oxc_codegen: Updated print_non_negative_float and get_minified_number functions to use dragonbox_ecma::Buffer

Technical Details

dragonbox_ecma was chosen over regular dragonbox because it provides ECMAScript-compliant formatting, which is essential for JavaScript/TypeScript tooling. The key challenge was that dragonbox_ecma only supports f64, while ryu_js supported both f32 and f64. The solution:

  1. Use dragonbox_ecma for all f64 formatting
  2. Use standard library formatting for most f32 values (which produces identical output to ryu_js)
  3. Special-case f32::MIN and f32::MAX to output scientific notation matching ryu_js

Testing

  • All existing serialization tests pass (28/28)
  • Float formatting produces identical output to ryu_js
  • Full project builds successfully
  • No breaking changes to public APIs

The migration maintains exact output compatibility while modernizing the floating point formatting dependency.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 5, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copilot AI changed the title [WIP] Replace the crate ryu_js to dragonbox. API for ryu_js is https://docs.rs/ryu-js/latest/ryu_js API for dragonbox is https://docs.rs/dragonbox/latest/dragonbox/ Replace ryu_js with dragonbox_ecma for floating point formatting Aug 5, 2025
Copilot AI requested a review from Boshen August 5, 2025 03:11
@github-actions github-actions bot added the A-codegen Area - Code Generation label Aug 5, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 5, 2025

CodSpeed Instrumentation Performance Report

Merging #12821 will improve performances by 4.24%

Comparing copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf (5da8abb) with main (00fda91)

Summary

⚡ 1 improvements
✅ 33 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
codegen[RadixUIAdoptionSection.jsx] 128.7 µs 123.5 µs +4.24%

@Boshen
Copy link
Member

Boshen commented Aug 5, 2025

@copilot update dragonbox_ecma to the latest version.

Copy link
Contributor Author

Copilot AI commented Aug 5, 2025

@copilot update dragonbox_ecma to the latest version.

Updated dragonbox_ecma from version 0.0.3 to 0.0.5. All tests pass including the 28 serialization tests. Build is successful with the latest version. (5772043)

@Boshen Boshen force-pushed the copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf branch from 5772043 to dc92c41 Compare August 5, 2025 15:50
@Boshen Boshen changed the title Replace ryu_js with dragonbox_ecma for floating point formatting perf(parser,codegen): Replace ryu_js with dragonbox_ecma for floating point formatting Aug 6, 2025
@Boshen Boshen changed the title perf(parser,codegen): Replace ryu_js with dragonbox_ecma for floating point formatting perf(syntax,codegen): Replace ryu_js with dragonbox_ecma for floating point formatting Aug 6, 2025
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Aug 6, 2025
@Boshen Boshen marked this pull request as ready for review August 6, 2025 04:50
@Boshen
Copy link
Member

Boshen commented Aug 6, 2025

Ran test262 and monitor-oxc, all passed.

@Boshen Boshen force-pushed the copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf branch from dc92c41 to a88a5d7 Compare August 6, 2025 04:50
Replace ryu_js with dragonbox_ecma for floating point formatting

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

[autofix.ci] apply automated fixes

Update dragonbox_ecma from 0.0.3 to 0.0.5

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
@Boshen Boshen force-pushed the copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf branch from a88a5d7 to cca1fd3 Compare August 6, 2025 04:58
@Boshen Boshen merged commit 2c4369a into main Aug 6, 2025
29 checks passed
@Boshen Boshen deleted the copilot/fix-b2eaa1cd-0a28-4aeb-8c39-90d74dc48baf branch August 6, 2025 05:16
This was referenced Aug 6, 2025
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments