Project

General

Profile

Actions

Feature #13827

closed

Improve performance of `Base64.urlsafe_encode64`

Added by Soilent (Konstantin x) over 6 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:82420]

Description

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

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

Actions

Also available in: Atom PDF

Like0
Like0Like0