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

Fix to support Ruby 3.0 Ractor #22

Merged
merged 1 commit into from
Jun 25, 2021
Merged

Fix to support Ruby 3.0 Ractor #22

merged 1 commit into from
Jun 25, 2021

Conversation

kvokka
Copy link
Contributor

@kvokka kvokka commented May 29, 2021

This PR is targeting to solve the same problem as #15 and some ideas are similar, but in contrast this one does not have the problem with multiple constant removal on the start up

https://bugs.ruby-lang.org/issues/17592

test/uri/test_common.rb Outdated Show resolved Hide resolved
@kvokka kvokka requested a review from mrkn May 31, 2021 07:45
@hsbt hsbt merged commit eb38236 into ruby:master Jun 25, 2021
@hsbt hsbt mentioned this pull request Jun 25, 2021
SCHEME_LIST_MUTEX.synchronize do
const_set(:SCHEMES, ObjectSpace.
each_object(Class).
select { |klass| klass < URI::Generic }.
Copy link
Member

Choose a reason for hiding this comment

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

This seems very expensive, iterate the whole heap when previously it was just registered directly.
Could the Class#inherited hook be used instead at least?
Or maybe use Class#descendants (checking if available with respond_to?) from https://bugs.ruby-lang.org/issues/14394?

In #15 I think the way was clearly to use instance variables for this, and that has been accepted in https://bugs.ruby-lang.org/issues/17592. And the main Ractor could simply write to that instance variable. That has not been implemented yet though (cc @ko1).

Another strategy might be to haves SCHEMES = {}, and then once the first URI is created, Ractor.make_shareable(SCHEMES) unless SCHEMES.frozen?. That would prevent adding new schemes after the first URI is created, but maybe it's good enough, and it feels like it fits well with the Ractor model.

Adding support for Ractor by making everything slower/more hacky is IMHO absolutely not acceptable.

end

# Re-calculate scheme list
def self.refresh_scheme_list
Copy link
Member

Choose a reason for hiding this comment

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

This is yet another hack, now the API exposes the caching to the end user, that's leaking implementation details.
It's ugly, there is no other word.

@eregon
Copy link
Member

eregon commented Jun 25, 2021

IMHO this should be reverted, or improved in a way that:

  • it does reassign constants
  • it does not use ObjectSpace.each_object

@eregon
Copy link
Member

eregon commented Jun 25, 2021

Yet another possibility, since we are going to break @@schemes['FOO'] = FOO anyway, how about simply limiting URI to the built-in schemes, and if needed provide a way to pass extra schemes e.g., via some Hash argument?

eregon added a commit to eregon/uri that referenced this pull request Jun 25, 2021
* This reverts commit 1faa4fd.
* It has too many problems, see ruby#22 for discussion.
@eregon
Copy link
Member

eregon commented Jun 25, 2021

I worked on a clean solution in #26

matzbot pushed a commit to ruby/ruby that referenced this pull request Jul 27, 2021
* This reverts commit 1faa4fdc161d7aeebdb5de0c407b923beaecf898.
* It has too many problems, see ruby/uri#22 for discussion.

ruby/uri@b959da2dc9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants