Skip to content

Instantly share code, notes, and snippets.

View byroot's full-sized avatar

Jean Boussier byroot

View GitHub Profile
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
gem "benchmark-ips"
end
require "benchmark/ips"
@byroot
byroot / _notes.md
Last active January 28, 2025 12:11

Things to know

  • Lobsters doesn't use Puma's preload_app! because it relies on phased restarts. This seem to cause massive GVL contention after a deploy.
  • Would be worth trying to exclude that data, but aside from the very begining it's not clear where deploys are in the dataset. Need to check with @pushcx.

Observations

  • The IO heavy requests are in the higher percentile.
  • IO heavy requests are the one suffering the most from GVL contention.
  • Which makes sense, the more IO you do, the more you need to re-acquire the GVL, so the most you suffer if it is contented.
require 'json'
path = ARGV.first
class Request
attr_reader :gc_ms, :run_ms, :idle_ms, :stall_ms, :io_percent, :method, :action
def initialize(hash)
@gc_ms = hash[:gc_ms]
@run_ms = hash[:run_ms]
src_count = frozen_src_count = 0
ARGV.each do |gem_path|
Dir.glob(File.join(gem_path, "**/*.rb")) do |file|
next unless File.file?(file) && File.readable?(file)
src_count += 1
frozen_src_count += 1 if File.binread(file) =~ /^# frozen[-_]string[-_]literal: (true|false)$/
end
end
require 'benchmark/ips'
require 'oj'
require 'json'
puts "Ruby version: #{RUBY_VERSION}"
puts "Oj version: #{Oj::VERSION}"
puts "JSON version: #{JSON::VERSION}"
json_encoder = JSON::State.new(JSON.dump_default_options)
# Sample data to hash - using varied data types
@byroot
byroot / idea.md
Created January 28, 2024 23:03
Relation refactoring idea
  • Extending -> record module and method_missing + bind_call (confirm that bind call doesn't allocate metaclass).
  • Single generic Relation class. Stop dynamic method generation.
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'benchmark-ips'
end
require 'benchmark/ips'
RubyVM::InstructionSequence.compile_option = { peephole_optimization: false }
class RubyVM::InstructionSequence
def self.load_iseq(path)
RubyVM::InstructionSequence.compile_file(path)
end
end
# Can be enabled with RUBYOPT="-r /path/to/disable_opt.rb"
@byroot
byroot / results.txt
Last active September 5, 2021 12:52
Impact of stack size on exceptions performance
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin17]
$ ruby yield-vs-block.rb
Nested yield stack size: 402
Forward block stack size: 202
Warming up --------------------------------------
baseline 82.138k i/100ms
nested-yield 16.030k i/100ms
forward-block 28.945k i/100ms
Calculating -------------------------------------
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "activerecord", "~> 5.2"