v0.16.5 : critical bug fixes
This release contains fixes of critical bugs that could lead to memory leaks in the user applications (depending on usage patterns).
The memory leak was introduced when we applied memoization in #455, which was an effort to reduce the memory footprint of Smithy4s on large APIs reusing the same datatypes all over the place. Unfortunately, we later realised that global memoization was unsafe, due to the instability of smithy4s.schema.Schema
(a GADT that contains thunks and lambda, and therefore is unstable wrt hashCode/equality and only responds to referential equality). The memory leak would happen every time the Smithy4s-routing would be stored in a def
that would re-execute on a per-request basis (which, really, was a user-side mistake, but it wouldn't be professional for us to leave a potential memory leak when the language doesn't give us the means to guarantee the user won't shoot themselves in the foot).
We didn't want to rollback the memoization, because a few applications we have internally at DisneyStreaming massively benefited from it, on the account of having large APIs with hundreds (if not thousand) datatypes. The memoization we had put in place has greatly helped the startup time of these applications, and their memory consumption, so just rolling back was not an option.
Instead, we've decided to take the time to apply a proper fix, and scope the memoization to the lifecycle of interpreters. This means that interpreters are responsible for instantiating their own Schema compilation cache, which gets GC'd when the interpreter is discarded.
Bug fixes
- Changes the memoization mechanism that could lead to memory leaks. Now memoization requires the injection of a cache instance, which is locally instantiated by http4s interpreters.
- Addresses a few bugs in the hint transformation function on schemas
- Discourages the inspection of the alternative contained by
Alt.WithValue
, in favour of using theAlt.Dispatcher
instance, which takes care of memoization for the implementor and offers a type-safe API.Alt.WithValue
is only ever-used on the encoding side of codecs, andAlt.Dispatcher
solves that exact problem in an arguably more elegant fashion. - Improve performance of erroring paths by memoizing the compilation of error schemas in the Http4s interpreter
- Applies the hint mask transitively in JsonCodecs (instead of locally).
What's Changed
- Fix hint transformations and adds a test suite by @Baccata in #524
- Move to coursier/setup-action by @daddykotex in #528
- Removing hint transformation in union's "total" function ... by @Baccata in #526
- Apply hint mask transitively in json codecs by @kubukoz in #521
- Amends the caching mechanism to avoid relying on global variables by @Baccata in #514
Full Changelog: v0.16.4...v0.16.5