Slide 1

Slide 1 text

Mike McQuaid (@MikeMcQuaid) Using "modern" Ruby to build a better, faster Homebrew

Slide 2

Slide 2 text

Background โฎ

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Mike McQuaid https://github.com/MikeMcQuaid https://mastodon.social/@mikemcquaid https://twitter.com/MikeMcQuaid

Slide 7

Slide 7 text

โค Homebrew and Ruby ๐Ÿ›  Homebrew Ruby Tools ๐Ÿบ Building Better brew

Slide 8

Slide 8 text

Homebrew and Ruby โค

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

โ€œHomebrew uses Ruby and some other stuff that is already installed on [Mac OS X] Leopard. Just copy this directory somewhere.โ€ @mxcl, 2009

Slide 11

Slide 11 text

To install the brew tool, do: $ ruby /Brewery/Cellar/homebrew/brewkit.rb

Slide 12

Slide 12 text

To install the brew tool, do: $ /bin/bash -c "$(curl -fsSL https:// raw.githubusercontent.com/Homebrew/ install/HEAD/install.sh)"

Slide 13

Slide 13 text

Install wget: $ ruby /Brewery/Formula/wget.rb

Slide 14

Slide 14 text

Install wget: $ brew install wget

Slide 15

Slide 15 text

Formula DSL ๐Ÿ’„

Slide 16

Slide 16 text

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 ๐Ÿ˜

Slide 17

Slide 17 text

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 ๐Ÿ˜

Slide 18

Slide 18 text

# 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 ๐Ÿ˜

Slide 19

Slide 19 text

Ruby 1.8.7 in 2009 ๐Ÿ™‚

Slide 20

Slide 20 text

Ruby 1.8.7 in 2016 ๐Ÿ˜ญ

Slide 21

Slide 21 text

Ruby 2.3 in 2017 ๐Ÿคจ

Slide 22

Slide 22 text

Ruby 2.3 in 2019 ๐Ÿ˜ 

Slide 23

Slide 23 text

Ruby 2.6 in 2019 ๐Ÿ˜ฎ๐Ÿ’จ

Slide 24

Slide 24 text

Ruby 2.6 in 2023 ๐Ÿคฌ

Slide 25

Slide 25 text

$ /usr/bin/ruby --version ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

Slide 26

Slide 26 text

No more Apple macOS Ruby ๐ŸŽ๐Ÿ‘‹๐Ÿ’Ž๐Ÿฅน

Slide 27

Slide 27 text

Ruby 3.1 in 2023 ๐Ÿ˜Œ

Slide 28

Slide 28 text

Ruby 3.3 in RubyKaigi 2024? ๐Ÿ˜…

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

$ brew config | grep Ruby Homebrew Ruby: 3.1.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby

Slide 31

Slide 31 text

Homebrew Ruby Tools ๐Ÿ› 

Slide 32

Slide 32 text

RuboCop ๐Ÿ‘ฎ

Slide 33

Slide 33 text

$ brew style wget 1 file inspected, no offenses detected

Slide 34

Slide 34 text

$ brew style Inspecting 1313 files .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. .................................................................................................................. ........................................................... 1313 files inspected, no offenses detected

Slide 35

Slide 35 text

Sorbet ๐Ÿง

Slide 36

Slide 36 text

$ brew typecheck No errors! Great job.

Slide 37

Slide 37 text

RSpec ๐Ÿงช

Slide 38

Slide 38 text

$ brew tests Randomized with seed 22584 10 processes for 437 specs, ~ 43 specs per process ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. .................................................................................................................................................................................................................... .............................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................... ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ............................................................................................................................................................................................................................................. ..................................................................................................................... ...................................................................................................................... .................................................................................................................................................................... . ...................................................................................................................................................................................................................... ............................................................................................................................................................................................................................................. ................................................................................................................................ .......................................................................................................... Took 391 seconds (6:31)

Slide 39

Slide 39 text

Building Better brew ๐Ÿบ

Slide 40

Slide 40 text

Building Better performance ๐ŸŽ

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

PROCRASTINATION ALERT โš 

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Porting to Rust ๐Ÿคจ

Slide 48

Slide 48 text

Porting to C ๐Ÿ˜ 

Slide 49

Slide 49 text

Porting to Bash ๐Ÿคฌ

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

hyperfine ๐Ÿงช

Slide 52

Slide 52 text

$ 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

Slide 53

Slide 53 text

$ 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

Slide 54

Slide 54 text

$ 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

Slide 55

Slide 55 text

$ 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

Slide 56

Slide 56 text

Building Better security ๐Ÿ”

Slide 57

Slide 57 text

Security Audit(s) ๐Ÿ•ต

Slide 58

Slide 58 text

GitHub Actions Attestation ๐Ÿ‘Œ

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

workbrew.com

Slide 65

Slide 65 text

โค Homebrew and Ruby ๐Ÿ›  Homebrew Ruby Tools ๐Ÿบ Building Better brew https://mikemcquaid.com/talks/using-modern-ruby-to-build-a-better-faster-homebrew/

Slide 66

Slide 66 text

Help Us! ๐Ÿค ๐ŸŽ Building Better performance ๐Ÿ” Building Better security

Slide 67

Slide 67 text

Questions? ๐Ÿ’œ @[email protected] @MikeMcQuaid [email protected]