Skip to content

Loading…

Perf tweaks side effects when inheriting from Gem::Version #805

Closed
rubiojr opened this Issue · 6 comments

2 participants

@rubiojr

Hiya,

It seems that the perf tweaks in 34fe654#diff-94d386526b8b558035d4e4c7602d647c are having some side effects when inheriting from Gem::Version:

class FooVersion < Gem::Version
end

v1 = FooVersion.new '1.2.3'
v2 = FooVersion.new '1.2.3'

puts v1.class # => FooVersion
puts v2.class # => FooVersion

v1 = FooVersion.new '1.2.3'
v2 = FooVersion.new '1.2.4'

puts v1.class # => FooVersion
puts v2.class # => Gem::Version

Among other things, overrided methods in FooVersion will not be called for v2 (instance of Gem::Version) leading to hard to debug issues.

@drbrain
RubyGems member

Out of curiosity, where are you using this?

@rubiojr

@drbrain we're using it internally in some projects to parse version strings.

Considering that most people will use other gems specialized in that (like the semantic gem) or simply not inheriting from it, this may not be an issue at all.

Just opened this to note the behavior change.

@drbrain
RubyGems member

Thanks.

I think I can fix the behavior change for your use.

@rubiojr

awesome, thanks.

@drbrain drbrain added a commit that closed this issue
@drbrain drbrain Restore Gem::Version::new behavior from < 2.1
Gem::Version::new used to return the same class as the input object but
now returns a Gem::Version if called with the same input from a
subclass.  This broke backward compatibility.

This broke from #447 which was a performance improvement change.
This commit maintains the same behavior except when Gem::Version was
subclassed and the version cache (which reduces GC) is skipped.

See #447 for the original commits

Fixes #805
81d806d
@drbrain drbrain closed this in 81d806d
@drbrain drbrain added a commit that referenced this issue
@drbrain drbrain Restore Gem::Version::new behavior from < 2.1
Gem::Version::new used to return the same class as the input object but
now returns a Gem::Version if called with the same input from a
subclass.  This broke backward compatibility.

This broke from #447 which was a performance improvement change.
This commit maintains the same behavior except when Gem::Version was
subclassed and the version cache (which reduces GC) is skipped.

See #447 for the original commits

Fixes #805
77f75f4
@drbrain
RubyGems member

Can you check master (or the 2.2 branch) with your application to make sure I fixed this properly?

@rubiojr

@drbrain yeah, it works as expected. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.