How expensive is it to create Procs and lambdas in ruby?

(answer: not expensive)

John Bachir's Code Blog
October 17, 2022

I recently implemented fancier around callbacks for ruby-clock. To do this sort of thing, you need to generate a Proc or lambda on the fly, so that each subsequent callback has something to .call. Procs and lambdas can't accept a block, so that's the only way to do it. Which is also a bit educational because you sort of end up . . .

Read More

Benchmarking various methods of accumulating a set / unique array in ruby

John Bachir's Code Blog
July 24, 2022

I recently benchmarked a few ways to accumulate a set in ruby. Here are my findings and methodology - apologies for messiness, I'm just sharing what I came up.

This is with ruby 3.1. I also ran under 2.7, I believe the set case was actually faster, but I may be misremembering.



 user system total . . .

Read More

You can't declare after_*_commit or after_commit callbacks for the same method more than once!


John Bachir's Code Blog
February 25, 2022

In Rails ActiveRecord, I just discovered that if you do this:

# bad code!
after_update_commit :thing
after_create_commit :thing

Only the second one will take effect! After asking in the rails slack, I was pointed to the docs which actually cover this:

Using both after_create_commit and after_update_commit . . .

Read More

Instrumenting and Scaling the Action Cable worker pool

John Bachir's Code Blog
January 06, 2022

Action Cable (aka ActionCable or action_cable) is a mature, useful stack of tech that allows easily integrating two-way communication in a Rails app via websockets.

There seems to be a complete lack of discussion on the web about instrumenting or scaling it. Here are my findings and experiments to that end so far.

The one . . .

Read More

How to install homebrew in a completely isolated environment

John Bachir's Code Blog
November 10, 2021

I'm a longtime macports fan and occasional evangelist. It Just Works, installs in /opt/local with sudo, and very frequently installs binaries instead of needing to build. Homebrew is widely used and supported and pretty great, but I always feel just a little better about using macports instead and haven't had a reason to switch.

. . .

Read More

Turning off ActiveRecord query cache to improve memory consumption in background jobs

John Bachir's Code Blog
October 17, 2021

The ActiveRecord query cache can defeat effective garbage collection when working on big batches of data. Disabling it entirely in background jobs can be a solid memory consumption win. Here's how to do it:



class SidekiqArCache
 def call(worker, msg, queue)
 ActiveRecord:: . . .

Read More

How to stop yourself from accidentally switching to a git branch named "master" instead of "main"

or vice-versa

John Bachir's Code Blog
October 02, 2021

If you have various projects which used either "main" or "master" as the main branch, and also have a remote which uses the other naming (e.g. heroku or another PaaS), you might find yourself accidentally switching to the wrong branch name and working on it. Here's how to inhibit that.

Put this in . . .

Read More

   Subscribe by email and never miss a post.

This update link alerts you to new Silvrback admin blog posts. A green bubble beside the link indicates a new post. Click the link to the admin blog and the bubble disappears.

Got It!