fs2 icon indicating copy to clipboard operation
fs2 copied to clipboard

Avoid boxing in `ScopedResource.State` internals

Open danicheg opened this issue 2 years ago • 3 comments

This is a dispensable performance tweak. The same workaround is already used in fs2, so it should be fine to reuse it once again. But I could be absolutely wrong on that. Don't hesitate to point me at that.

danicheg avatar Feb 13 '23 17:02 danicheg

@danicheg So, if we are to have classes with null fields, then at least we should contain that nullability. Thus, we should make State into a normal class and add to the companion object two factory methods (or apply), one with and one without the finaliser parameter.

Also, do we have a measure or an intuition as to how many State objects with a different finaliser would be built during the compilation of a Stream, as a function of the number of Pull nodes (of any special type)?

diesalbla avatar Feb 13 '23 17:02 diesalbla

For these types of changes, where the code is arguably harder to read/work with as a result of the optimization, I'd really like to see benchmarks that prove the performance gain pays off.

mpilquist avatar Feb 13 '23 18:02 mpilquist

That's absolutely fair to ask for numbers to accept any unsafety. I don't know what the hell got into me to bring this PR without a benchmark 😥

danicheg avatar Feb 13 '23 18:02 danicheg