Commit graph

76 commits

Author SHA1 Message Date
Hartley McGuire
9b49ba5a68
[rubygems/rubygems] Speed up Version#<=> ~20-50% when lengths differ
Previously, the comparison code would loop through segments up to the
longest of the two versions being compared. However, this is inefficient
because once one version has more segments than the other we can do a
lot less work.

This commit optimizes the differing segment length case by specializing
the logic once the iteration has passed the shorter of the two segment
lengths. At this point we only need to continue looking at the longer
version's segment, and we know that any String encountered means the
version is less than (pre), and any non-zero Integer means the version
is greater than.

Benchmark:

```
{
  first: [Gem::Version.new("1.2.3"), Gem::Version.new("2.2.3")],
  second: [Gem::Version.new("1.2.3"), Gem::Version.new("1.3.3")],
  third: [Gem::Version.new("1.2.3"), Gem::Version.new("1.2.4")],
  length: [Gem::Version.new("1.2.3"), Gem::Version.new("1.2.3.4")],
  left_s_second: [Gem::Version.new("1.a.3"), Gem::Version.new("1.2.3")],
  left_s_third: [Gem::Version.new("1.2.a"), Gem::Version.new("1.2.3")],
  right_s_second: [Gem::Version.new("1.2.3"), Gem::Version.new("1.a.3")],
  right_s_third: [Gem::Version.new("1.2.3"), Gem::Version.new("1.2.a")],
  left_s_length: [Gem::Version.new("8.0.1.pre"), Gem::Version.new("8.0.1")],
  right_s_length: [Gem::Version.new("8.0.1"), Gem::Version.new("8.0.1.pre")],
  both_s: [Gem::Version.new("8.0.2.pre1"), Gem::Version.new("8.0.2.pre2")],
}.each do |name, v|
  puts "== #{name} =="

  raise name unless v[0].fast_comp(v[1]) == (v[0] <=> v[1])

  Benchmark.ips do |x|
    x.report("fast") { v[0].fast_comp(v[1]) }
    x.report("original") { v[0] <=> v[1] }
    x.compare!(order: :baseline)
  end
end

== first ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   208.555k i/100ms
            original   199.789k i/100ms
Calculating -------------------------------------
                fast      2.075M (± 6.0%) i/s  (481.93 ns/i) -     10.428M in   5.055818s
            original      2.045M (± 3.9%) i/s  (488.94 ns/i) -     10.389M in   5.090034s

Comparison:
                fast:  2075002.8 i/s
            original:  2045227.4 i/s - same-ish: difference falls within error

== second ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   192.395k i/100ms
            original   183.000k i/100ms
Calculating -------------------------------------
                fast      1.892M (± 3.8%) i/s  (528.62 ns/i) -      9.620M in   5.094104s
            original      1.824M (± 3.5%) i/s  (548.11 ns/i) -      9.150M in   5.023163s

Comparison:
                fast:  1891722.2 i/s
            original:  1824435.3 i/s - same-ish: difference falls within error

== third ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   172.788k i/100ms
            original   162.934k i/100ms
Calculating -------------------------------------
                fast      1.719M (± 9.0%) i/s  (581.72 ns/i) -      8.467M in   5.025861s
            original      1.638M (± 3.6%) i/s  (610.36 ns/i) -      8.310M in   5.080344s

Comparison:
                fast:  1719042.9 i/s
            original:  1638389.6 i/s - same-ish: difference falls within error

== length ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   191.741k i/100ms
            original   155.952k i/100ms
Calculating -------------------------------------
                fast      1.920M (± 3.9%) i/s  (520.74 ns/i) -      9.587M in   5.002328s
            original      1.576M (± 6.2%) i/s  (634.42 ns/i) -      7.954M in   5.072507s

Comparison:
                fast:  1920362.1 i/s
            original:  1576240.9 i/s - 1.22x  slower

== left_s_second ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   176.441k i/100ms
            original   164.879k i/100ms
Calculating -------------------------------------
                fast      1.609M (± 7.3%) i/s  (621.51 ns/i) -      8.116M in   5.083414s
            original      1.620M (± 8.3%) i/s  (617.43 ns/i) -      8.079M in   5.028525s

Comparison:
                fast:  1608994.8 i/s
            original:  1619606.5 i/s - same-ish: difference falls within error

== left_s_third ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   160.562k i/100ms
            original   152.799k i/100ms
Calculating -------------------------------------
                fast      1.591M (± 3.6%) i/s  (628.40 ns/i) -      8.028M in   5.052029s
            original      1.528M (± 3.6%) i/s  (654.31 ns/i) -      7.640M in   5.007526s

Comparison:
                fast:  1591334.1 i/s
            original:  1528320.6 i/s - same-ish: difference falls within error

== right_s_second ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   135.938k i/100ms
            original   132.907k i/100ms
Calculating -------------------------------------
                fast      1.367M (± 1.2%) i/s  (731.77 ns/i) -      6.933M in   5.074030s
            original      1.320M (± 2.4%) i/s  (757.35 ns/i) -      6.645M in   5.036155s

Comparison:
                fast:  1366548.7 i/s
            original:  1320386.4 i/s - same-ish: difference falls within error

== right_s_third ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   129.971k i/100ms
            original   123.802k i/100ms
Calculating -------------------------------------
                fast      1.273M (± 4.1%) i/s  (785.25 ns/i) -      6.369M in   5.011805s
            original      1.215M (± 1.8%) i/s  (823.04 ns/i) -      6.190M in   5.096330s

Comparison:
                fast:  1273487.0 i/s
            original:  1215002.9 i/s - same-ish: difference falls within error

== left_s_length ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   211.093k i/100ms
            original   155.784k i/100ms
Calculating -------------------------------------
                fast      2.120M (± 1.9%) i/s  (471.63 ns/i) -     10.766M in   5.079336s
            original      1.565M (± 6.7%) i/s  (638.87 ns/i) -      7.789M in   5.007522s

Comparison:
                fast:  2120296.1 i/s
            original:  1565258.0 i/s - 1.35x  slower

== right_s_length ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   213.977k i/100ms
            original   142.990k i/100ms
Calculating -------------------------------------
                fast      2.154M (± 1.3%) i/s  (464.15 ns/i) -     10.913M in   5.066124s
            original      1.446M (± 1.8%) i/s  (691.75 ns/i) -      7.292M in   5.046172s

Comparison:
                fast:  2154455.3 i/s
            original:  1445607.9 i/s - 1.49x  slower

== both_s ==
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
Warming up --------------------------------------
                fast   154.903k i/100ms
            original   131.011k i/100ms
Calculating -------------------------------------
                fast      1.515M (± 4.0%) i/s  (659.97 ns/i) -      7.590M in   5.019890s
            original      1.280M (± 5.3%) i/s  (781.28 ns/i) -      6.420M in   5.035387s

Comparison:
                fast:  1515223.3 i/s
            original:  1279957.8 i/s - 1.18x  slower
```

7195e77152
2025-03-18 09:42:38 +09:00
David Rodríguez
9e0eb9778d Merge RubyGems-3.6.2 and Bundler-2.6.2 2024-12-24 07:21:10 +09:00
David Rodríguez
30eba40f9c [rubygems/rubygems] Remove to_yaml_properties
This is an old syck thing, no longer used anywhere.

6f72d02bac
2024-07-24 19:55:04 +00:00
David Rodríguez
a4d80eee17 [rubygems/rubygems] Let RuboCop target Ruby 3.0
70243b1d72
2023-11-13 11:06:10 +09:00
Martin Emde
9dcaa83259 [rubygems/rubygems] Avoid excess Arrays when partitioning Gem::Version.canonical_segments
338c48f935
2023-10-11 22:18:46 +00:00
Samuel Giddins
bf71b0eda5 [rubygems/rubygems] Optimize allocations in Gem::Version
From running in a random rails app I have locally, here are the changes

1) for `bundle lock --update --bundler` (forcing Bundler to go through
dependency resolution)

```
==> memprof.after.txt <==
Total allocated: 2.98 MB (48307 objects)
Total retained:  1.21 MB (16507 objects)

==> memprof.before.txt <==
Total allocated: 12.62 MB (198506 objects)
Total retained:  1.30 MB (23133 objects)
```

2) for `bin/rails runner true` (essentially only bundler/setup)

```
==> memprof.after.txt <==
Total allocated: 59.50 kB (1017 objects)
Total retained:  25.08 kB (362 objects)

==> memprof.before.txt <==
Total allocated: 561.82 kB (8575 objects)
Total retained:  27.28 kB (513 objects)
```

35c8ed2cb8
2023-10-07 16:04:42 +00:00
Josef Šimánek
25b536cc2f
[rubygems/rubygems] Fix invalid links in documentation. - wrap ENV variables in <code> - fix rubygems.org link - fix zenspider.com link
9eaac94a63
2023-10-03 16:13:18 +09:00
Hiroshi SHIBATA
827d66266b [rubygems/rubygems] auto-correct Style/YodaCondition
6d9e8025dc
2023-06-15 07:01:28 +09:00
Hiroshi SHIBATA
a881b33818 [rubygems/rubygems] util/rubocop -A --only Performance/RegexpMatch
52ae4452c2
2023-04-04 12:20:43 +00:00
Hiroshi SHIBATA
2e3cd1dc3e [rubygems/rubygems] Enabled Style/RedundantReturn cop
05cc97bdf8
2023-03-23 17:18:49 +09:00
Hiroshi SHIBATA
2db7673825 [rubygems/rubygems] util/rubocop -A --only Style/DoubleNegation
01c2b5542f
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
3d4c3f9e4f [rubygems/rubygems] util/rubocop -A --only Style/ParallelAssignment
5c88c77873
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
83f9aa8f02 [rubygems/rubygems] util/rubocop -A --only Style/Alias
fba6e94de9
2023-03-17 18:50:55 +09:00
Samuel Giddins
638f68b2fe [rubygems/rubygems] Avoid calling String#dup in Gem::Version#marshal_dump
Might potentially save a second every time RubyGems.org creates a specs index

d6e4d50f8d
2023-03-07 11:48:41 +00:00
Hiroshi SHIBATA
a43f1d90c2 Merge RubyGems and Bundler master
from 0635c1423d
2023-01-10 15:53:07 +09:00
Hiroshi SHIBATA
44264b4fee Merge rubygems/bundler HEAD.
Pick from dfbb5a3811
2022-08-09 12:05:19 +09:00
David Rodríguez
20936eb3a9 [rubygems/rubygems] Warn (rather than crash) when setting nil specification versions
a4ba1a4d97
2022-08-03 06:56:18 +09:00
Takuya Noguchi
d7ffd3fea4
RubyGems: Enable Style/StringLiterals cop
Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2022-07-22 12:07:23 +09:00
David Rodríguez
ba38318827 [rubygems/rubygems] Unify loading Gem::Requirement
It was being explicitly required from `Gem::Specification` but also a
strange autoload was set for it at `Gem::Version`. The autoload was non
standard because it should've been done in the `Gem` module, not in
`Gem::Specification`, since that's where the constant is expected to get
defined. Doing this might get deprecated in the future, and it was not
being effective anyways due to the explicit require.

Unify everything with an `autoload` at the right place.

174ea3e24c
2022-06-06 18:36:31 +09:00
nicholas a. evans
981a75db91 [rubygems/rubygems] Fix missing rdoc for Gem::Version
The rdoc for Gem::Version is available here:
* https://docs.ruby-lang.org/en/3.0/Gem/Version.html

However it is currently missing from:
* https://ruby-doc.org/stdlib-3.1.0/libdoc/rubygems/rdoc/Gem/Version.html
* https://docs.ruby-lang.org/en/3.1/Gem/Version.html
* https://docs.ruby-lang.org/en/master/Gem/Version.html
* `ri Gem::Version`
  with `ri --version` => 6.4.0 and `gem --version` => 3.3.5
* `yard ri Gem::Version` with `yard --version` => 0.9.27

c10e5dd884
2022-02-07 23:06:19 +09:00
David Rodríguez
f04954d95c
[rubygems/rubygems] Normalize end alignment style with Bundler
f7f504b24c
2022-01-19 11:20:36 +09:00
Akira Matsuda
9828502570 [rubygems/rubygems] Let Version#spaceship accept a String
With this patch, handwriting version comparisons become a little bit easier.

before:
  SomeGem.version <=> Gem::Version.new('1.3')

after:
  SomeGem.version <=> '1.3'

7e0dbb79f2
2022-01-13 18:15:14 +09:00
Hiroshi SHIBATA
7e084ed707 Merge RubyGems and Bundler master
Merge from 793ad95ecb
2021-12-15 18:05:18 +09:00
David Rodríguez
d044ffd77f [rubygems/rubygems] Allow using Gem::Version without loading the rest of rubygems
1b862537a5
2021-12-06 18:43:29 +09:00
Hiroshi SHIBATA
b717f73402
Revert "Manually merged from https://github.com/rubygems/rubygems/pull/2636"
31a6eaabc1 is obsoleted with
  https://github.com/rubygems/rubygems/pull/3820
2020-09-23 22:01:44 +09:00
Hiroshi SHIBATA
31a6eaabc1
Manually merged from https://github.com/rubygems/rubygems/pull/2636
Enable Style/EmptyLinesAroundClassBody rubocop cop.
2020-09-23 21:02:56 +09:00
David Rodríguez
a89665b7b1 Enforce no empty lines around class body in rubygems
To normalize the code style with `bundler`.
2020-07-31 21:07:19 +09:00
David Rodríguez
955f1837a1 Use space inside block braces everywhere
To make rubygems code style consistent with bundler.
2020-06-15 21:20:37 +09:00
David Rodríguez
061add792e
[rubygems/rubygems] Enable Style/ExtraSpacing and auto-correct
6fa0b1b679
2020-03-30 12:48:23 +09:00
Hiroshi SHIBATA
600a715c9b
Merge the current master branch of rubygems/rubygems.
Just started to develop RubyGems 3.2.0.
2020-02-01 11:14:57 +09:00
Hiroshi SHIBATA
7d463e360b Merge RubyGems 3.1.0.pre3
* Fix gem pristine not accounting for user installed gems. Pull request
    #2914 by Luis Sagastume.
  * Refactor keyword argument test for Ruby 2.7. Pull request #2947 by
    SHIBATA Hiroshi.
  * Fix errors at frozen Gem::Version. Pull request #2949 by Nobuyoshi
    Nakada.
  * Remove taint usage on Ruby 2.7+. Pull request #2951 by Jeremy Evans.
  * Check Manifest.txt is up to date. Pull request #2953 by David Rodríguez.
  * Clarify symlink conditionals in tests. Pull request #2962 by David
    Rodríguez.
  * Update command line parsing to work under ps. Pull request #2966 by
    David Rodríguez.
  * Properly test `Gem::Specifications.stub_for`. Pull request #2970 by
    David Rodríguez.
  * Fix Gem::LOADED_SPECS_MUTEX handling for recursive locking. Pull request
    #2985 by MSP-Greg.
2019-11-11 16:59:49 +09:00
David Rodríguez
d9e6315177
[rubygems/rubygems] Bump rubocop to 0.74.0 and fix new offenses
d4fc383497
2019-09-05 18:48:15 +09:00
David Rodríguez
d0a5467320 Update rubygems with latest upstream changes
Closes: https://github.com/ruby/ruby/pull/2154
2019-04-28 11:07:45 +09:00
hsbt
4ae3df42f7 Merge RubyGems master@9be7858f7f17eae3058204f3c03e4b798ba18b9c
This version contains the some style changes by RuboCop.

    * 9d810be0ed
    * 61ea98a727
    * 795893dce3
    * 9be7858f7f

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-14 12:59:03 +00:00
mame
f7e94df0d6 lib/rubygems: explicitly clarify the type for =~ matching
RubyGems is very indifferent for type.
This change is needed for removal of `Object#=~`.  [Feature #15231]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26 07:13:53 +00:00
hsbt
5335ce0e06 Merge master branch from rubygems/rubygems upstream.
* Enable Style/MethodDefParentheses in Rubocop
    https://github.com/rubygems/rubygems/pull/2478
  * Enable Style/MultilineIfThen in Rubocop
    https://github.com/rubygems/rubygems/pull/2479
  * Fix required_ruby_version with prereleases and improve error message
    https://github.com/rubygems/rubygems/pull/2344
  * Fix bundler rubygems binstub not properly looking for bundler
    https://github.com/rubygems/rubygems/pull/2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-21 10:20:47 +00:00
hsbt
615ac35934 Merge rubygems master branch from github.com/rubygems/rubygems.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22 00:27:02 +00:00
hsbt
85d461456c Merge master branch from rubygems upstream.
* It's preparation to release RubyGems 3.0.0.beta2 and Ruby 2.6.0
    preview 3.
  * https://github.com/rubygems/rubygems/compare/v3.0.0.beta1...fad2eb15a282b19dfcb4b48bc95b8b39ebb4511f

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-27 10:05:04 +00:00
hsbt
c6da9cadb3 Merge RubyGems 2.7.7
see release details here: https://blog.rubygems.org/2018/05/18/2.7.7-released.html

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-18 01:39:13 +00:00
hsbt
c00e84327f Merge rubygems master.
This is RC version of Rubygems 2.7.0.
  688fb7e83c

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-08 01:32:18 +00:00
hsbt
5d43821536 Update Rubygems 2.6.10
* 2ee5bf9fd3
 * be510dd409

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-24 02:38:57 +00:00
nobu
b6139464f5 rubygems 2.6.7
* lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update
  rubygems to 2.6.7, not the master, with r56225.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-28 01:16:43 +00:00
nobu
69934aeb8d rubygems 2.6.7
* lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update
  rubygems to 2.6.7.
  Release note of 2.6.7: 60f35bd1d2

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-28 00:57:53 +00:00
hsbt
5a90f9e8f8 * lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2.6.1.
Please see entries of 2.6.0 and 2.6.1 on
  https://github.com/rubygems/rubygems/blob/master/History.txt
  [fix GH-1270] Patch by @segiddins

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-04 00:29:40 +00:00
hsbt
a21d403f21 * lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2.5.2.
It supports to enable frozen string literal and add `--norc` option for
  disable to `.gemrc` configuration.
  See 2.5.2 release notes for other fixes and enhancements.
  a8aa3bac72/History.txt (L3)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53707 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-01 12:43:26 +00:00
naruse
3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
hsbt
0c5841bead * lib/rubygems: Update to RubyGems 2.5.1
* test/rubygems: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-11 02:53:09 +00:00
hsbt
effdbf5936 * lib/rubygems: Update to RubyGems HEAD(c202db2).
this version contains many enhancements see http://git.io/vtNwF
* test/rubygems: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-07-01 21:50:14 +00:00
hsbt
d9c32d62a0 * lib/rubygems: Update to RubyGems 2.4.6 and HEAD(800f2e6).
Fixed #1159, #1171, #1173 on rubygems/rubygems
* test/rubygems: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-27 13:00:45 +00:00
hsbt
4de117a615 * lib/rubygems: Update to RubyGems 2.4.1 master(713ab65)
Complete history at:
  https://github.com/rubygems/rubygems/blob/master/History.txt#L3-L216
* test/rubygems:  ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-14 03:30:02 +00:00