Skip to content

Comment on Algorithms for converting binary to decimal floating-point numbers (2021)

Comments

In Java, many number-to-string implementations use NumberFormat. This is abysmally slow if the problem domain doesn't require internationalization, which is the case for machine-readable file formats, such as SVG. When I performance tested JMathTeX for rendering TeX, one major bottleneck for converting TeX into SVG elements was JFreeSVG's use of NumberFormat. Replacing NumberFormat with RyuDouble doubled the throughput[0]. (Reusing a StringBuilder to concatenate strings yielded another doubling.)

For KeenType[1], a fork of the New Typesetting System (and more complete plain TeX implementation than JMathTeX), I added an SVG generator that converts floating point numbers to strings using a StackOverflow answer[2], not the Ryu algorithm[3]. Better performance, simpler algorithm.

Knuth's advice holds: measure then optimize.

[0]: https://github.com/jfree/jfreesvg/pull/30

[1]: https://github.com/DaveJarvis/KeenType

[2]: https://stackoverflow.com/a/10554128/59087

[3]: https://github.com/DaveJarvis/KeenType/blob/fef005579021f394...

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.