Skip to content

Fix issue#8199#8201

Merged
headius merged 1 commit intojruby:masterfrom
ryannevell:master
Apr 24, 2024
Merged

Fix issue#8199#8201
headius merged 1 commit intojruby:masterfrom
ryannevell:master

Conversation

@ryannevell
Copy link
Contributor

This PR fixes the issue described in #8199, adds 2 new test cases, and removes tags for 2 existing, disabled test cases

@headius
Copy link
Member

headius commented Apr 24, 2024

Very nice!

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever fix. If I'm reading it right, you avoid the confusion between passing nil and passing no arguments by adding an extra always-ignored nil into the Fiber.yield. That allows us to detect whether nil was passed explicitly or implicitly and the rest of the logic remains fairly simple even with the fix in place.

I have a minor concern that all Enumerator#next will now produce an array internally, usually immediately unwrapping it, but that's an optimization issue for another day.

@headius headius merged commit 261b6ad into jruby:master Apr 24, 2024
@ryannevell
Copy link
Contributor Author

ryannevell commented Apr 24, 2024

The additional, always-ignored nil into Fiber.yield is because Fiber.yield has very similar behavior to next, and implicitly unwraps arrays of size 1 if that's the only arg given.

As for the performance concern, I actually don't think there's any additional array unwrapping. In the previous code, there was:

@result = object.__send__ method, *args do |*vals|
ret = Fiber.yield(*vals)

so that splat into Fiber.yield(*vals) was previously doing the array unwrapping. In the new code, the vals array is passed straight through Fiber.yield(vals, nil) and returned from next_values to finally be unwrapped in next. So it should be the same number of allocations and unwraps.

I could imagine some performance degradation due to the additional call, tho, since next now calls next_values. I did not attempt to benchmark this change.

@headius
Copy link
Member

headius commented Apr 24, 2024

I did not attempt to benchmark this change.

You are right... there's already a lot of argument array-juggling so if anything has changed it's probably a lateral move. I have not benchmarked this code much at all so it's an open project to investigate that (and likely the hottest pieces would need to move to Java code to improve performance).

Thanks for the fix!

@ryannevell
Copy link
Contributor Author

I'm thrilled to give back. Thanks for all your hard work on JRuby, it's a fantastic project.

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.

3 participants