issues
search
joshmfrankel
/
joshmfrankel.github.io
Blog and Personal site
http://joshfrankel.me
MIT License
2
stars
1
forks
source link
Performance tips
#57
Open
joshmfrankel
opened
1 year ago
joshmfrankel
commented
1 year ago
Db
avoid plucking ids/select ids instead
only select what you need
ar is lazy eval use this to build sql
always filter with where clause
arel tables for complexity
indexes
explain analyze
a single query is generally faster than multiple
ruby
only iterate collections once if possible
memorize expensive logic
write conditionals least expensive first including compound and if elsif
hashmap for lookups
Avoid using sleep
watch for n+1 style code
benchmark with big data
eager load to avoid n+1
find_in_batches to avoid loading all into memory etc
.exists? > .any? > .present? for ActiveRecord collections
.any? / .one? vs .all? / .none?
Jobs
Collection All > One job standard to defer multiple processing
Async for non-critical operations
Only retry if not doing so would cause problems
tests
don't create when you can build
group test setup with like tests
unit > integration > feature
request specs with Capybara
Stub external systems
Don't make http calls
js
debounce or throttle expensive events
memoize
Db
ruby
Jobs
tests
js