Skip to content

Instantly share code, notes, and snippets.

ruby 3.3.0dev (2023-03-14T07:07:59Z master ac65ce16e9) [aarch64-linux]
-------------- ----------- ---------- --------- ---------- ----------- ------------
bench interp (ms) stddev (%) yjit (ms) stddev (%) interp/yjit yjit 1st itr
activerecord 206.9 0.9 97.5 1.3 2.12 0.62
hexapdf 4940.6 1.0 2415.3 2.2 2.05 1.20
liquid-c 88.9 2.0 61.9 3.4 1.44 0.30
liquid-render 300.5 1.7 135.3 3.1 2.22 0.64
mail 209.0 0.6 104.6 3.7 2.00 0.32
psych-load 4474.7 0.3 1887.1 0.1 2.37 2.24
railsbench 2794.2 0.5 1544.4 1.5 1.81 0.74
RUBY_T_MASK = 0x1f
RUBY_T_STRING = 0x05
RUBY_T_ARRAY = 0x07
RSTRING_EMBED_LEN_SHIFT = 0x0e
RSTRING_EMBED_LEN_MASK = 0x7c000
RSTRING_NOEMBED = 0x2000
RARRAY_EMBED_FLAG = 0x2000
RARRAY_EMBED_LEN_SHIFT = 0x0f
RARRAY_EMBED_LEN_MASK = 0x18000
RUBY_ID_SCOPE_SHIFT = 0x4
#include <errno.h>
#include <sched.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
int main_parent(pid_t child_pid) {
@KJTsanaktsidis
KJTsanaktsidis / gist:80a7005cd0784f73b83ab121b1b82cc9
Created January 24, 2023 11:47
Renaming an anonymous class in Ruby...
kj@kj-thinkpad ~ % cat rename.rb
#!/usr/bin/env ruby
require 'fiddle'
libruby = Fiddle::Handle.new
rb_set_class_path_string = Fiddle::Function.new(
libruby['rb_set_class_path_string'],
[
Fiddle::TYPE_UINTPTR_T,
@KJTsanaktsidis
KJTsanaktsidis / curl_parallel.c
Created November 21, 2022 06:57
glibc dns timeout reproduction
#include <curl/curl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define NUM_THREADS 20
static pthread_mutex_t outlock = PTHREAD_MUTEX_INITIALIZER;
@KJTsanaktsidis
KJTsanaktsidis / riak.lua
Created November 17, 2022 09:47
Wireshark protocol dissector for Riak
-- Riak protocol decoder
-- Based on copypasta from https://wiki.wireshark.org/Protobuf.md
-- To use,
-- * Plase in ~/.local/lib/wireshark/plugins/riak.lua
-- * Check out https://github.com/protocolbuffers/protobuf somewhere
-- * Check out https://github.com/basho/riak_pb somewhere
-- * In the "ProtoBuf" protocol preferences, add protobuf/src and riak_pb/src
-- to the search paths. Make sure "load all" is checked for riak_pb, but NOT
-- for protobuf.
-- * right click a stream -> decode as -> "RIAK_PROTO"
With memocache:
kj@kj-thinkpad ruby_memprofiler_pprof % ruby script/benchmark.rb
user system total real
no profiling (1) 15.844936 0.469273 16.314209 ( 16.337021)
no profiling (2) 14.966771 0.034934 15.001705 ( 15.020942)
with profiling (1%, no flush) 15.971306 0.477258 16.448564 ( 16.471195)
with reporting (1%, with flush) 17.402173 0.029948 17.432121 ( 17.454925)
with profiling (10%, no flush) 23.168302 0.289576 23.457878 ( 23.487329)
with reporting (10%, with flush) 48.194583 0.042943 48.237526 ( 48.290087)
@KJTsanaktsidis
KJTsanaktsidis / gist:ac4d7bf85bceb171e39f5c5534771995
Created June 13, 2022 06:42
Apparently it's slow because of marking everything?
Samples: 8K of event 'cycles', Event count (approx.): 367381525322, DSO: ruby_memprofiler_pprof_ext.so
Children Self Comm Symbol
+ 60.45% 0.00% ruby [.] collector_cdata_gc_mark ▒
+ 60.34% 0.03% ruby [.] collector_gc_mark_each_heap_sample ▒
+ 60.30% 0.26% ruby [.] mpp_sample_gc_mark ▒
+ 0.74% 0.00% ruby [.] collector_tphook_newobj ▒
0.04% 0.00% ruby [.] collector_tphook_freeobj ▒
0.02% 0.01% ruby [.] mpp_rb_gc_disable_no_rest ▒
0.01% 0.01% ruby [.] backtracie_bt_gc_mark_moveable@plt
kj@kj-thinkpad ruby_memprofiler_pprof % ruby script/benchmark.rb
user system total real
no profiling (1) 15.867480 0.473907 16.341387 ( 16.382863)
no profiling (2) 14.955051 0.031678 14.986729 ( 15.025699)
with profiling (1%, no flush) 22.981310 0.484232 23.465542 ( 23.501221)
with reporting (1%, with flush) 24.261126 0.057177 24.318303 ( 24.353663)
with profiling (10%, no flush) 109.202573 0.291814 109.494387 (109.596998)
with reporting (10%, with flush) 154.720902 0.060936 154.781838 (154.920858)
@KJTsanaktsidis
KJTsanaktsidis / gist:21d7ed46251fbd87bfa14cccbe704133
Created June 13, 2022 00:58
Backtrace showing st_table doing ruby_xmalloc
#0 heap_page_add_freeobj (objspace=0xeb9800, page=0x153da2c0, obj=139975204190960) at gc.c:1850
#1 0x00007f4e98cf35ab in gc_sweep_plane (objspace=0xeb9800, heap=0xeb9838, p=139975204190960, bitset=1, ctx=0x7ffe5ff47e20) at gc.c:5293
#2 0x00007f4e98cf39ad in gc_sweep_page (objspace=0xeb9800, size_pool=0xeb9828, heap=0xeb9838, ctx=0x7ffe5ff47e20) at gc.c:5389
#3 0x00007f4e98cf3f89 in gc_sweep_step (objspace=0xeb9800, size_pool=0xeb9828, heap=0xeb9838) at gc.c:5665
#4 0x00007f4e98cf485d in gc_sweep (objspace=0xeb9800) at gc.c:5900
#5 0x00007f4e98cf8c49 in gc_marks_rest (objspace=0xeb9800) at gc.c:8100
#6 0x00007f4e98cf8daf in gc_marks (objspace=0xeb9800, full_mark=0) at gc.c:8151
#7 0x00007f4e98cfae13 in gc_start (objspace=0xeb9800, reason=512) at gc.c:8967
#8 0x00007f4e98cfaa8a in garbage_collect (objspace=0xeb9800, reason=512) at gc.c:8853
#9 0x00007f4e98cfb567 in garbage_collect_with_gvl (objspace=0xeb9800, reason=512) at gc.c:9225