Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Using "modern" Ruby to build a better, faster H...

Using "modern" Ruby to build a better, faster Homebrew

Learn why Homebrew now ships its own Ruby, modern Ruby tooling we rely on, how to make Homebrew faster and how we are improving Homebrew.

Presented at RubyKaigi 2024.

Mike McQuaid

May 17, 2024
Tweet

More Decks by Mike McQuaid

Other Decks in Programming

Transcript

  1. “Homebrew uses Ruby and some other stuff that is already

    installed on [Mac OS X] Leopard. Just copy this directory somewhere.” @mxcl, 2009
  2. To install the brew tool, do: $ /bin/bash -c "$(curl

    -fsSL https:// raw.githubusercontent.com/Homebrew/ install/HEAD/install.sh)"
  3. class Wget < Formula desc "Internet file retriever" homepage "https://www.gnu.org/software/wget/"

    url "https://ftp.gnu.org/gnu/wget/wget-1.24.5.tar.gz" sha256 "fa2dc35bab5184ecbc46a9ef83def2aaaa3f4c9f3c97d4bd19dcb07d4da637de" license "GPL-3.0-or-later" def install system "./configure", "--prefix=#{prefix}" system "make", "install" end test do system bin/"wget", "-O", "/dev/null", "https://google.com" end end 😍
  4. cask "1password" do arch arm: "aarch64", intel: "x86_64" version "8.10.30"

    sha256 arm: "0d2ea809dafab2b17e7622faf1ada03ac912e31fae8f58bc0ed2f7b9a6b1bff2", intel: "ba70b5733e68a1276ee02b1feff75a0b23dd332dff2e9ddaefa07b4c16bf5579" url "https://downloads.1password.com/mac/1Password-#{version}-#{arch}.zip" name "1Password" desc "Password manager that keeps all passwords secure behind one password" homepage "https://1password.com/" auto_updates true depends_on macos: ">= :catalina" app "1Password.app" end 😍
  5. # typed: strict # frozen_string_literal: true require "abstract_command" module Homebrew

    module Cmd class Docs < AbstractCommand cmd_args do description <<~EOS Open Homebrew's online documentation at <#{HOMEBREW_DOCS_WWW}> in a browser. EOS end sig { override.void } def run exec_browser HOMEBREW_DOCS_WWW end end end end 😍
  6. $ brew config | grep Ruby Homebrew Ruby: 3.1.4 =>

    /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
  7. $ brew style Inspecting 1313 files .................................................................................................................. .................................................................................................................. .................................................................................................................. ..................................................................................................................

    .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. ........................................................... 1313 files inspected, no offenses detected
  8. $ brew tests Randomized with seed 22584 10 processes for

    437 specs, ~ 43 specs per process ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. .................................................................................................................................................................................................................... .............................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................... ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ..................................................................................................................... ...................................................................................................................... .................................................................................................................................................................... . ...................................................................................................................................................................................................................... ............................................................................................................................................................................................................................................. ................................................................................................................................ .......................................................................................................... Took 391 seconds (6:31)
  9. $ hyperfine "brew --prefix" Benchmark 1: brew --prefix Time (mean

    ± σ): 440.4 ms ± 13.2 ms [User: 138.0 ms, System: 84.0 ms] Range (min … max): 426.4 ms … 463.0 ms 10 runs
  10. $ hyperfine "brew --prefix" Benchmark 1: brew --prefix Time (mean

    ± σ): 34.6 ms ± 4.3 ms [User: 5.1 ms, System: 5.9 ms] Range (min … max): 26.6 ms … 42.8 ms 49 runs
  11. $ hyperfine "brew command install" Benchmark 1: brew command install

    Time (mean ± σ): 474.6 ms ± 42.0 ms [User: 144.9 ms, System: 91.4 ms] Range (min … max): 429.8 ms … 553.2 ms 10 runs
  12. $ hyperfine "brew command install" Benchmark 1: brew command install

    Time (mean ± σ): 39.1 ms ± 12.3 ms [User: 5.0 ms, System: 5.8 ms] Range (min … max): 21.8 ms … 97.4 ms 65 runs
  13. ❤ Homebrew and Ruby 🛠 Homebrew Ruby Tools 🍺 Building

    Better brew https://mikemcquaid.com/talks/using-modern-ruby-to-build-a-better-faster-homebrew/