Skip to content

Evaluate a Żmij-style shortest float/double producer for CoreLib #134638

Closed as not planned

Description

@akeit0

Proposal

I propose adapting the shortest-decimal producer in ZmijSharp at b2b9ef3 for CoreLib’s unconstrained-precision float and double formatting. It supplies digits and scale to the existing number buffer and presentation path, with no public API change.

The producer uses Victor Zverovich's original Żmij as its algorithmic reference. It offers two cached-power profiles: compact stores less data, while full avoids cache reconstruction.

Local performance

The benchmark measures canonical double significand and exponent production. Unrounded scaling is a local double specialization of the shortest path from #131068; its adaptation notes are in the repository. Setup checks that all three producers return the same result for every input.

Windows 11 x64, .NET SDK 11.0.100-rc.1.26425.128, BenchmarkDotNet DefaultJob; 10,000 deterministic finite, nonzero values per corpus. Results are mean ns/value (lower is better). All cases reported zero managed allocations.

Corpus Żmij compact Żmij full Unrounded scaling
Varied long significands 8.049 5.613 6.817
Random raw IEEE bits 10.055 6.164 8.613
Simple values 18.354 15.215 15.160

The full profile is faster on the first two corpora and similar on simple values. The compact profile uses less data but takes longer on all three. These measurements cover decomposition, before digit writing and text presentation. Full results, variation, and reproduction command.

Data and code size

The minimal Release net11.0 DLLs use the same project and public adapter.

Measure Żmij compact Żmij full Unrounded scaling
Raw cached-power constants 830 B 9,888 B 11,136 B
Shortest.Core.dll file length 12,288 B 20,480 B 19,968 B
Listed x64 JIT instruction bytes 1,562 B 1,383 B 1,391 B

DLL lengths include PE layout, metadata, and IL. The JIT row covers the listed call tree from one x64 run. These figures are not incremental CoreLib size estimates. The size record identifies the counted constants and methods.

Correctness

The standalone formatter matched the installed .NET 11 RC runtime’s default invariant char output for all 2³² binary32 encodings. A deterministic 100-million-pattern binary64 sample matched default char and UTF-8 output. Sampled and exponent-boundary cases also passed an independent exact-integer shortest-decimal oracle. Coverage and commands.

A matched CoreLib build would establish complete formatting performance and incremental size impact.

Activity

  1. added
    untriaged
    on Sep 25, 2026
  2. dotnet-policy-service commented on Sep 25, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-numerics
    See info in area-owners.md if you want to be subscribed.

  3. changed the title [-]Evaluate a compact Żmij-style shortest float/double producer alongside #131068[/-] [+]Evaluate a Żmij-style shortest float/double producer for CoreLib[/+] on Sep 25, 2026
  4. Mrnikbobjeff commented on Sep 25, 2026

    @Mrnikbobjeff

    FYI I have integrated this change in the RYU branch and will have a full bench comparison in an hour since I found one double test bug and managed to optimize the reference US algorithm and the RYU reference algorithm to always beat US. Both are written in the runtime style as well, eliding the unsafe code you have in your reference implementation

  5. Mrnikbobjeff commented on Sep 25, 2026

    @Mrnikbobjeff

    Benchmarks (mean ns; usc = PR #131068, ryu = spacing‑28 Ryu, zmij = compact, zfull = full table)

    benchmark value base usc ryu zmij zfull zmij/ryu zfull/zmij
    Canada 17‑digit coords 67.9 54.0 51.6 55.1 47.3 1.07 0.86
    Synthetic 66.6 55.2 53.9 57.4 50.0 1.07 0.87
    RandomBits 88.7 65.7 66.8 69.9 60.7 1.05 0.87
    Mesh small ints 47.8 45.8 35.0 51.1 43.8 1.46 0.86
    RandomInt 63.9 61.6 44.5 60.7 55.0 1.37 0.91
    RandomShort 65.4 61.2 51.5 68.5 61.2 1.33 0.89
    ToString 104 42.3 45.9 26.3 57.2 48.5 2.18 0.85
    ToString 0.1 37.9 43.4 40.0 51.7 48.6 1.29 0.94
    ToString 1E+23 159.3 47.6 43.2 54.5 49.7 1.26 0.91
    ToString double.MaxValue 78.6 65.6 60.3 62.1 55.2 1.03 0.89
    CanadaF float 52.1 36.7 42.1 39.4 35.7 0.94 0.91
    RandomBitsF 73.0 49.2 57.6 54.3 48.0 0.94 0.89
    MeshF 45.8 34.0 32.3 39.6 32.5 1.23 0.82
    ToString 104f 40.9 34.7 27.0 42.6 36.0 1.58 0.84
    AllHalf (Ryu on all) 56.9 33.8 34.4 34.2 34.8 — —

    I can port the small number optimization I had in ryu to this, then the benchmark results should favor you even more. I would adapt this and then change the existing pr

  6. removed
    untriaged
    on Sep 29, 2026
  7. locked and limited conversation to collaborators on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions