Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further optimize ch exec read #8775

Merged
merged 14 commits into from
Apr 24, 2024

Conversation

eyalfa
Copy link
Contributor

@eyalfa eyalfa commented Apr 21, 2024

  1. few more optimizations on top of ZPipeline.fromFunction benchmark and optimization #8761

initial benchmark results:

Benchmark                                     (chunkCount)  (chunkSize)   Mode  Cnt    Score   Error  Units
StreamBenchmarks.zioChunkToConstBaseline             10000         5000  thrpt   15  148.078 ± 4.111  ops/s
StreamBenchmarks.zioChunkToConstDirect               10000         5000  thrpt   15  232.269 ± 2.481  ops/s
StreamBenchmarks.zioChunkToConstFromFunction         10000         5000  thrpt   15  133.889 ± 0.352  ops/s

after applying the optimizations:

[info] Benchmark                                     (chunkCount)  (chunkSize)   Mode  Cnt    Score   Error  Units
[info] StreamBenchmarks.zioChunkToConstBaseline             10000         5000  thrpt   15  244.041 ± 1.084  ops/s
[info] StreamBenchmarks.zioChunkToConstDirect               10000         5000  thrpt   15  366.264 ± 1.715  ops/s
[info] StreamBenchmarks.zioChunkToConstFromFunction         10000         5000  thrpt   15  245.392 ± 1.611  ops/s

optimization techniques applied:

  1. ChannelExecutor.readUpstream
    a. make the internal read method tail recursive
    b. instead of suspending on each recurse, count consecutive operations and suspend every N steps (currently set to 128), this is important in order to keep the stream interruptible.
    c. reduce stack mutations by separating the current Read from the rest, for some reads this means they'd never make it into the stack, for others it avoids pushing the same read immediately after popping it from the stack.
  2. ChannelExecutor.execToPullingChannel, implement readUpstream as a channel. this avoids going through effects for some code paths and eliminate the need for the onSuccess and onFailure effects.
  3. reorder cases in ChannelExecutor.run, make sure frequent channel constructors appear earlier in the pattern matching.

@eyalfa
Copy link
Contributor Author

eyalfa commented Apr 21, 2024

@ghostdogpr I'd appreciate your review on this

@ghostdogpr
Copy link
Member

ghostdogpr commented Apr 21, 2024

@ghostdogpr I'd appreciate your review on this

I'm completely unfamiliar with ZStream internals. Not sure who is, maybe @jdegoes ?

@eyalfa
Copy link
Contributor Author

eyalfa commented Apr 22, 2024

@vigoo seems like you were on of the last to touch this area, can u please review?

@eyalfa
Copy link
Contributor Author

eyalfa commented Apr 23, 2024

@jdegoes , @vigoo , can u please review this?

@jdegoes jdegoes merged commit c63f983 into zio:series/2.x Apr 24, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants