Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
7% improvement in Schedule. Useful for low periodic timers, such as those used in ZStream.groupedWithin.
It is fairly rare that durations of timer are low enough to notice the difference in an overall application, but with a high-throughput stream that also wants to keep latency low for the downstream consumer, it is noticeable. Removing the throw stops having to fill a stack trace and throw in the normally code path where the Schedule upper-bound is OffsetDateTime.Max. An alternative change could be to substract the delta from Max and compare with interval.end. However this approach has two downsides. 1) it is not clear from the original code if overflow is the only cause of exception. 2) there is more work done on the happy path to do the subtractions then to simply compare.
Below is a benchmark showing an (unrealistically) low duration on pretty fast desktop that shows a 7% uplift in ops/s:
With the current ZIO head:
With the patched version
I didn't add the benchmark to the StreamBenchmarks as I am not sure it is worth carrying forward for such a specific case, but happy to add/refine if you fancy merging the PR
This optimization is low risk, albeit for little returns for most ZIO users.