TIL, 2018-02-06
Musings
- HN/Rust: Skylight uses an agent embedded in Rails applications. Ruby = high memory, C++ = high risk of crashes.
- 92% smaller than Ruby agent.
Optimize Rails performance bottleneck with caching and Rack middleware
- Redis for slow AR queries. For Heroku, you can have Redis to Go.
- Sidekiq Cron used to update the cache every half an hour.
- A Redis hit means no database query and also reduces memory usage because you don’t need to instantiate ActiveRecord objects.
- Rack middleware: You can create your own middleware, so that the app doesn’t pass through Rails.
Limit Rails memory usage, fix R14 and save money on Heroku
gem derailed_benchmarks
to see which gems consume a lot of memory.jemalloc
as an alternative to the official MRI memory allocator.- Limiting concurrency and workers. Just 1?
- Optimize JSON parsing?
gem yaji-ruby
.
Ruby under a Microscope
defs/keywords
contains all the keywords in Ruby.redo
andretry
are used to execute parts of the loop.redo
repeats the current iteration,retry
repeats the whole loop from the start. Referenceundef
apparently is a reserved word, but how would you use it?- Reference
- Reference
- This is used in things like mocking.
- Rails codebase: Used for testing the behavior of classes with and without modules mixed-in.
- This can be used for blocking a class explicitly defined in the superclass.
- For mixins: you can include the whole mixin, but remove the methods it shouldn’t support. Ex: in the graphics library
shoes
, thebutton
class mixes inclickable
, butundef
’s therelease
method because buttons don’t support it.
- You can sort of include methods dynamically.
Form.send(:include, FormExportingMethods)
if you really need to.
99 Bottles of OOP
- Shameless green.
- Transformation Priority Premise: It makes sense, but it’s like, too robot-like/nuanced?
- Tests: Sometimes it’s just better to test the hardcoded strings rather than pass through a function.