zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
800 stars 403 forks source link

Optimizations for request execution happy path #3143

Closed kyri-petrou closed 2 months ago

kyri-petrou commented 2 months ago

Main changes:

  1. Convert Routes to Handler in ServerInboundHandler to avoid allocations & method invocations each time we call Routes#apply.
  2. Store the wildcards tree in RoutePattern in a val to avoid doing that on each invocation to RoutePattern#get
  3. Use Map#getOrElse(key, null) in a couple of places
  4. Extract tree outside of the Function1 in toHandler to avoid checking the class var on each request
  5. Use null as the default for Set[Int] in PathCodec#get. This avoids the boxing of the Int on each iteration.

Note on (5): We could also use BitSet here, but since almost always skipLiteralsFor will be empty / null, it's better to avoid the method invocation and just do a null check

jdegoes commented 2 months ago

Nice work! Can't believe (1) wasn't already done. 🤦‍♂️