Feature #20707
closedMove `Time#xmlschema` into core
Description
Performance¶
Converting Time
into RFC3339 / ISO8601
representation is an significant hotspot for application that serialize data in JSON, XML or other formats.
Right now this feature is currently available through the time
default gem, so it rely on Time#strftime
.
While strftime
could certainly be optimized, ultimately it's a very generic API so can't make a lot of assumptions about the output.
Whereas ISO8601
is a very strict format, with very few dynamic part, so it's much easier for dedicated code to be well optimized, as the final size of the string can be computed upfront etc.
compare-ruby: ruby 3.4.0dev (2024-08-29T13:11:40Z master 6b08a50a62) +YJIT [arm64-darwin23]
built-ruby: ruby 3.4.0dev (2024-08-30T13:17:32Z native-xmlschema 34041ff71f) +YJIT [arm64-darwin23]
warming up......
| |compare-ruby|built-ruby|
|:-----------------------|-----------:|---------:|
|time._xmlschema | 1.087M| 5.190M|
| | -| 4.78x|
|utc_time._xmlschema | 1.464M| 6.848M|
| | -| 4.68x|
|time._xmlschema(6) | 859.960k| 4.646M|
| | -| 5.40x|
|utc_time._xmlschema(6) | 1.080M| 5.917M|
| | -| 5.48x|
|time._xmlschema(9) | 893.909k| 4.668M|
| | -| 5.22x|
|utc_time._xmlschema(9) | 1.056M| 5.707M|
| | -| 5.40x|
Usability¶
Aside from the performance reason, ISO8601
is so common that having this functionality built-in without needing to require anything would make sense to me.
xmlschema
is the most common reason why I require time
, and in many case having it core would allow not to load it at all.