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

Proof of Concept: Automatically store strings as raw values #938

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Nov 29, 2022

  1. Proof of Concept: Automatically store strings as raw

    When a value is already a String, there is little point using Marshal
    to serialize it. The only benefit is to properly presserve the String
    encoding, but this can instead be stored as a bitflag on the key.
    
    On a simple benchmark reading a 1MB UTF-8 string, it's about twice faster.
    
    ```ruby
    
    require 'bundler/inline'
    
    gemfile do
      source "https://rubygems.org"
      gem "dalli"
      gem "benchmark-ips"
    end
    
    require "dalli"
    require "benchmark/ips"
    
    client = Dalli::Client.new("localhost", compress: false)
    payload = "B" * 1_000_000
    client.set("key", payload)
    Benchmark.ips do |x|
      x.report("get 1MB UTF-8") { client.get("key") }
    end
    ```
    
    ```
    $ ruby /tmp/benchmark-dalli.rb
    Warming up --------------------------------------
           get 1MB UTF-8   156.000  i/100ms
    Calculating -------------------------------------
           get 1MB UTF-8      1.582k (± 2.7%) i/s -      7.956k in   5.031764s
    $ ruby -Ilib /tmp/benchmark-dalli.rb
    Warming up --------------------------------------
           get 1MB UTF-8   280.000  i/100ms
    Calculating -------------------------------------
           get 1MB UTF-8      2.798k (± 4.3%) i/s -     14.000k in   5.012061s
    ```
    
    This is inspired by my work on our in-house serializer library:
    Shopify/paquito#20
    byroot committed Nov 29, 2022
    Configuration menu
    Copy the full SHA
    8a21ff9 View commit details
    Browse the repository at this point in the history