Ruby Conf 2024
HTML for performance
- less 2000nodes, warnings at 800 nodes
- max depth of 32 nodes
- dont use divs
- cumulative layout shift
- img .. loaging=”lazy”
- !!! do not lazy load LCP (Largest ..)
- prioritisation is very important on http 2/3
fetchpriority
: high / low / auto(default) high / low will only raise to specfied amount, not max - use in img carousels, etc
<link rel="preconnect"
-> 100ms gains- only for critical fetches
- for rest use
<link rel="dns-prefetch"
<link rel="preload"
on critical- for fonts, css, large vids/files
- not for ordinary media
Anti-patterns
SQL / n+1 / optimisation
bullet
gem- strict loading
rack-minni-profiler
andstackprof
gems
Law of Demeter
order.smth.name
order.smth.other.name
order.smth.other.date
order.try(:smth).try(:name)
Fibres vs Threads
avoiding deadlock with threads
- acquire lock in order
- set timeout
- use appropriate data structs
avoiding deadlock with fibres
- fibres needs explicit
yeild
- fibres needs explicit
interrupts
fibres
less succeptible to interrupts
handle interrupts in threads
- use flags
- maintain timeouts
- use
thread#kill
- maintain queue
threads
- complex to debug
fibres
- no native parallelism support
fibres
aren’t useful in compute heavy operations
thread
are not good at optimizing CPU utilization
fibres
need explicit coordination
fibres
has no shared memory(share mem leads to issues)
Ractors
async, async-http, async-io
- gem, built on top of fibres
falcon
- server
Scaling Redis writes with Cluster mode
way to deploy Redis
- 1:1 - Rails:Redis
- Redis Sentinel: high availability (old school) - works out of the box with redis gem.
- Cons: no way to scale writes
- Pros: can sxale reads from stale replica. no single point of filure
- Redis::Distributed: A-K, L-Z
- Redis::Distributed + Redis Sentinel
- problem: node scaling. A-K, L-Z, ???
- Redis Cluster (gem)
- 16384 slots
crc16(key)
- each slot is assigned to one master node and some replica nodes
cons: complicates client lib support to correctly handle redirections
- 16384 slots
Leave a comment