Skip to content

Instantly share code, notes, and snippets.

View casperisfine's full-sized avatar

Jean byroot Boussier casperisfine

View GitHub Profile
require 'benchmark/ips'
require 'active_support/all'
class CVarBase
mattr_accessor :legacy_connection_handling, instance_writer: false, default: true
def self.connection_handlers
unless legacy_connection_handling
raise NotImplementedError, "The new connection handling does not support accessing multiple connection handlers."
end
require 'active_support/all'
require 'benchmark/ips'
class Module
def fake_cattr_accessor(sym)
private_getter = :"_#{sym}"
private_setter = :"_#{sym}="
singleton_class.attr_accessor(private_getter)
singleton_class.send(:private, private_getter, private_setter)
# frozen_string_literal: true
require 'benchmark/ips'
require 'active_support/all'
require 'zlib'
sizes = if ENV['SIZES']
ENV['SIZES'].split(',').map(&:to_i)
else
[0, 10, 2_000]
# frozen_string_literal: true
require "bigdecimal/util"
# Ref: https://github.com/ruby/ruby/commit/e1424c35012ccf1f3822c9046081b225aef4142e
# Ref: https://github.com/ruby/bigdecimal/issues/70
# Ruby 3.0 changed the default precision used when calling `Float#to_d` from 15 to 16.
# It causes a whole lot of issues. I'm trying to figure out what can be done about it
# but in the meantime the only solution I see is to revert it back to 2.x behavior.
if RUBY_VERSION >= "3.0"
require "benchmark/ips"
require "active_support/all"
class Hash
def refined_symbolize_keys
transform_keys { |key| key.to_sym rescue key }
end
end
module HashRefinements
require "set"
require "objspace"
module DeepMemsize
class << self
def memsize_of(object, seen = Set.new.compare_by_identity)
return 0 unless seen.add?(object)
size = ObjectSpace.memsize_of(object)
object.instance_variables.each { |v| size += memsize_of(object.instance_variable_get(v), seen) }
/tmp/bundle/ruby/3.1.0/bundler/gems/mysql2-8193dc412c6a/lib/mysql2/client.rb:148: [BUG] Segmentation fault at 0x000000000015613a
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0060 p:---- s:0354 e:000353 CFUNC :_query
c:0059 p:0012 s:0348 e:000347 BLOCK /tmp/bundle/ruby/3.1.0/bundler/gems/mysql2-8193dc412c6a/lib/mysql2/client.rb:148 [FINISH]
c:0058 p:---- s:0345 e:000344 CFUNC :handle_interrupt
c:0057 p:0036 s:0340 e:000339 METHOD /tmp/bundle/ruby/3.1.0/bundler/gems/mysql2-8193dc412c6a/lib/mysql2/client.rb:147
c:0056 p:0008 s:0334 e:000333 METHOD /app/lib/patches/01_mysql_monitoring.rb:6
c:0055 p:0007 s:0328 e:000327 BLOCK /tmp/bundle/ruby/3.1.0/gems/semian-0.11.8/lib/semian/mysql2.rb:82

Plan for redis-rb 5.0

A large part of redis-rb maintenance cost comes from having to implement each command Redis add. A year after Redis 6.2 release, we're still missing a large part of the newly added commands, and tengentially commands added by Redis modules are hard to use.

This comes down to the RESP2 protocol that requires to know how to parse each command output.

However Redis 6.0 introduced the RESP3 protocol, which is properly typed allowing clients to not know anything about the commands they are sending, which means a drastically simpler and smaller implementation that don't need keeping up with commands added upstream.

#!/bin/sh
set -eu
AGGRESSIVE=0
PARAMS=""
while [ "$#" -gt 0 ]; do
case "$1" in
--aggressive)
require 'objspace'
require 'json'
class Foo
class_eval <<~RUBY
def initialize
#{21.times.map { |i| "@attr_#{i} = #{i}" }.join("\n")}
end
RUBY