zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Replace Netty based RFC 1123 date encoding (#3527)

Open 987Nabil opened this issue 6 months ago • 6 comments

fixes #3527 /claim #3527

987Nabil avatar Jun 13 '25 15:06 987Nabil

Deploy Preview for zio-http ready!

Name Link
Latest commit cac56dd45586c670fba852ff525b9fe44cb39796
Latest deploy log https://app.netlify.com/projects/zio-http/deploys/685c1b980c93cd000808ad5d
Deploy Preview https://deploy-preview-3550--zio-http.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Jun 13 '25 15:06 netlify[bot]

Here is an efficient implementation of parsing/formatting for different timestamp formats including RFC 1123. Most performance tricks were ported from jsoniter-scala routines for JSON parsing and serialization of different data time values.

Java's DateTimeFormatter is ~10x times slower and affects scalability by eating memory bandwidth greatly. Even when using caching for formatting it introduces much bigger tail latency during refreshing of formatted values.

plokhotnyuk avatar Jun 14 '25 09:06 plokhotnyuk

@guizmaii Implemented some benchmarks

Before your suggested changes

Benchmark                                      Mode  Cnt        Score         Error  Units
DateEncodingBenchmark.nettyDecoding           thrpt    3   439288.041 ± 1092690.136  ops/s
DateEncodingBenchmark.nettyDecodingInvalid    thrpt    3   427059.216 ±  895231.682  ops/s
DateEncodingBenchmark.nettyEncoding           thrpt    3   635390.868 ± 1403521.676  ops/s
DateEncodingBenchmark.zioHttpDecoding         thrpt    3  2317595.133 ± 2830576.722  ops/s
DateEncodingBenchmark.zioHttpDecodingInvalid  thrpt    3  2443173.737 ±  219913.014  ops/s
DateEncodingBenchmark.zioHttpEncoding         thrpt    3  1095266.738 ±  378289.638  ops/s

After

Benchmark                                      Mode  Cnt         Score         Error  Units
DateEncodingBenchmark.nettyDecoding           thrpt    3    471698.844 ±  401495.065  ops/s
DateEncodingBenchmark.nettyDecodingInvalid    thrpt    3    433314.955 ±  208199.739  ops/s
DateEncodingBenchmark.nettyEncoding           thrpt    3    596804.828 ± 1649578.829  ops/s
DateEncodingBenchmark.zioHttpDecoding         thrpt    3   2327353.872 ± 2900047.041  ops/s
DateEncodingBenchmark.zioHttpDecodingInvalid  thrpt    3  17922976.451 ± 3374509.274  ops/s
DateEncodingBenchmark.zioHttpEncoding         thrpt    3   1054091.409 ± 1728102.469  ops/s

The invalid case has explicitly strings with invalid length.

987Nabil avatar Jun 20 '25 18:06 987Nabil

Cool job! Although why not make these changes in Netty code for everyone to benefit?

nau avatar Jun 22 '25 14:06 nau

@nau

Although why not make these changes in Netty code for everyone to benefit?

I can be wrong but I think the idea is probably to have this code in pure Scala so that it compiles to JS and Native and reduces the dependency on Netty

guizmaii avatar Jun 24 '25 02:06 guizmaii

@nau @guizmaii There are two reasons.

  1. We want to be independent of Netty. Not only for JS/Native, but also to be able to offer different backends in the JVM.
  2. Nettys formatter supports not only RFC1123 dates. We can optimize here by failing for any other date then RFC1123 dates

987Nabil avatar Jun 25 '25 13:06 987Nabil