[ruby-core:96184] [Ruby master Feature#13827] Improve performance of `Base64.urlsafe_encode64`

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83061.20191210053458.2fb1e80ec822b4f8@ruby-lang.org>
Issue #13827 has been updated by mame (Yusuke Endoh).

Status changed from Open to Closed

Merged at 1bdabaa6b13344c195698ca5b0ced323cb93e2e1.  Thank you for the contribution.

----------------------------------------
Feature #13827: Improve performance of `Base64.urlsafe_encode64`
https://bugs.ruby-lang.org/issues/13827#change-83061

* Author: Soilent (Konstantin x)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Improve performance of `Base64.urlsafe_encode64` by avoiding unnecessary memory allocations. This may seem insignificant, but for the web service I am working on this patch makes noticeable improvement.

### Benchmark

~~~ ruby
require 'benchmark/ips'
require 'base64'
require 'securerandom'

Benchmark.ips do |x|
  string = SecureRandom.bytes(128)

  x.report 'Base64.urlsafe_encode64' do |t|
    t.times { Base64.urlsafe_encode64(string) }
  end
end
~~~

### Before
                               
~~~
Base64.urlsafe_encode64                                                                   
                        559.355k (± 3.2%) i/s -      2.805M in   5.019239s               
~~~ 

### After

~~~
Base64.urlsafe_encode64
                        736.211k (± 2.5%) i/s -      3.721M in   5.057606s
~~~

### Patch

https://github.com/ruby/ruby/pull/1676



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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.