From eb8364d24856782f08aa2e6a756244ba3448ef69 Mon Sep 17 00:00:00 2001 From: Thomas Klemm Date: Fri, 6 Nov 2026 21:10:41 +0000 Subject: [PATCH] Add a blog benchmark that writes The Rails benchmarks here mostly read. In their timed iterations none of them submits a form, fails a validation, or runs after-commit callbacks and broadcasts; lobsters' only writes are its read-ribbon bookkeeping. Real apps spend much of their time saving records: validations, callbacks, transactions, INSERT/UPDATE/DELETE and enqueuing jobs. The app is the one the create-blog script from Sam Ruby's Roundhouse (roundhouse-rb/roundhouse, MIT or Apache-2.0, used here under MIT) builds: rails new --css tailwind on Rails 8.1.4.1, with Article and Comment scaffolds, validations and Turbo broadcasts. It keeps the production defaults of rails new: SQLite, Solid Cache, Solid Queue, Solid Cable, Propshaft and importmap, no external services. The built Tailwind CSS is checked in, so no CSS build runs. benchmarks/blog/README.md lists the changes to the generated tree. Generated files that only deployment, development, tests or a web server use are left out: .kamal/, config/deploy.yml, bin/ except rails and rake, public/, test/, the development and test environments, the Puma, recurring-task, CI, bundler-audit and RuboCop config, Procfile.dev, db/migrate (db/schema.rb creates the tables), the PWA views, the mailer and its layouts, ApplicationJob, the empty helpers and the .keep files in lib/, script/, vendor/, log/, tmp/, app/assets/images/ and the concerns/ directories. Every response is the same without them. The Gemfile keeps its default group without kamal, thruster, puma, bootsnap and tailwindcss-rails, since the app runs in-process and the CSS is already built; setup installs 43 fewer gems. Each iteration runs 200 seeded visits in-process, like railsbench: reads (index, show, JSON) and writes (create, update and delete articles, add and delete comments, a create that fails validation with 422). Writes submit the CSRF token from the page's form, as a browser does, and every response's status is checked, along with a body marker or the redirect target. The iteration runs in one transaction per database that is rolled back at the end, as in Rails tests, so every iteration sees the same rows and IDs. Rails 8.1 opens that transaction in pin_connection!; since rails/rails 9e8fe3955b it no longer does, so benchmark.rb opens it itself when none is open, and works on both. Time.now starts at a fixed date and advances one second per visit, so the work doesn't depend on the date and updates still write updated_at. Saves run as savepoints inside that transaction, and their after-commit callbacks run when the savepoint is released, as in Rails tests. Solid Cable inserts each broadcast in the request rather than on its batching writer thread, so it lands in the transaction; the later broadcasts are enqueued into Solid Queue. Since nothing commits, a real COMMIT is not measured. --- benchmarks.yml | 2 + benchmarks/blog/.gitignore | 40 ++ benchmarks/blog/Gemfile | 24 ++ benchmarks/blog/Gemfile.lock | 341 ++++++++++++++++++ benchmarks/blog/LICENSE | 21 ++ benchmarks/blog/README.md | 58 +++ benchmarks/blog/Rakefile | 6 + benchmarks/blog/app/assets/builds/.keep | 0 .../blog/app/assets/builds/tailwind.css | 2 + .../app/assets/stylesheets/application.css | 10 + .../blog/app/assets/tailwind/application.css | 1 + .../app/controllers/application_controller.rb | 7 + .../app/controllers/articles_controller.rb | 70 ++++ .../app/controllers/comments_controller.rb | 28 ++ benchmarks/blog/app/javascript/application.js | 3 + .../app/javascript/controllers/application.js | 9 + .../controllers/hello_controller.js | 7 + .../blog/app/javascript/controllers/index.js | 4 + .../blog/app/models/application_record.rb | 3 + benchmarks/blog/app/models/article.rb | 10 + benchmarks/blog/app/models/comment.rb | 15 + .../blog/app/views/articles/_article.html.erb | 16 + .../app/views/articles/_article.json.jbuilder | 2 + .../blog/app/views/articles/_form.html.erb | 27 ++ .../blog/app/views/articles/edit.html.erb | 10 + .../blog/app/views/articles/index.html.erb | 31 ++ .../app/views/articles/index.json.jbuilder | 1 + .../blog/app/views/articles/new.html.erb | 9 + .../blog/app/views/articles/show.html.erb | 52 +++ .../app/views/articles/show.json.jbuilder | 1 + .../blog/app/views/comments/_comment.html.erb | 7 + .../app/views/layouts/application.html.erb | 31 ++ benchmarks/blog/benchmark.rb | 203 +++++++++++ benchmarks/blog/bin/rails | 4 + benchmarks/blog/bin/rake | 4 + benchmarks/blog/config.ru | 6 + benchmarks/blog/config/application.rb | 27 ++ benchmarks/blog/config/boot.rb | 3 + benchmarks/blog/config/cable.yml | 19 + benchmarks/blog/config/cache.yml | 16 + benchmarks/blog/config/database.yml | 40 ++ benchmarks/blog/config/environment.rb | 5 + .../blog/config/environments/production.rb | 93 +++++ benchmarks/blog/config/importmap.rb | 7 + benchmarks/blog/config/initializers/assets.rb | 7 + .../initializers/content_security_policy.rb | 29 ++ .../initializers/filter_parameter_logging.rb | 8 + .../blog/config/initializers/inflections.rb | 16 + benchmarks/blog/config/locales/en.yml | 31 ++ benchmarks/blog/config/queue.yml | 18 + benchmarks/blog/config/routes.rb | 7 + benchmarks/blog/config/storage.yml | 27 ++ benchmarks/blog/db/cable_schema.rb | 10 + benchmarks/blog/db/cache_schema.rb | 12 + benchmarks/blog/db/queue_schema.rb | 160 ++++++++ benchmarks/blog/db/schema.rb | 31 ++ benchmarks/blog/db/seeds.rb | 35 ++ benchmarks/blog/storage/.keep | 0 58 files changed, 1666 insertions(+) create mode 100644 benchmarks/blog/.gitignore create mode 100644 benchmarks/blog/Gemfile create mode 100644 benchmarks/blog/Gemfile.lock create mode 100644 benchmarks/blog/LICENSE create mode 100644 benchmarks/blog/README.md create mode 100644 benchmarks/blog/Rakefile create mode 100644 benchmarks/blog/app/assets/builds/.keep create mode 100644 benchmarks/blog/app/assets/builds/tailwind.css create mode 100644 benchmarks/blog/app/assets/stylesheets/application.css create mode 100644 benchmarks/blog/app/assets/tailwind/application.css create mode 100644 benchmarks/blog/app/controllers/application_controller.rb create mode 100644 benchmarks/blog/app/controllers/articles_controller.rb create mode 100644 benchmarks/blog/app/controllers/comments_controller.rb create mode 100644 benchmarks/blog/app/javascript/application.js create mode 100644 benchmarks/blog/app/javascript/controllers/application.js create mode 100644 benchmarks/blog/app/javascript/controllers/hello_controller.js create mode 100644 benchmarks/blog/app/javascript/controllers/index.js create mode 100644 benchmarks/blog/app/models/application_record.rb create mode 100644 benchmarks/blog/app/models/article.rb create mode 100644 benchmarks/blog/app/models/comment.rb create mode 100644 benchmarks/blog/app/views/articles/_article.html.erb create mode 100644 benchmarks/blog/app/views/articles/_article.json.jbuilder create mode 100644 benchmarks/blog/app/views/articles/_form.html.erb create mode 100644 benchmarks/blog/app/views/articles/edit.html.erb create mode 100644 benchmarks/blog/app/views/articles/index.html.erb create mode 100644 benchmarks/blog/app/views/articles/index.json.jbuilder create mode 100644 benchmarks/blog/app/views/articles/new.html.erb create mode 100644 benchmarks/blog/app/views/articles/show.html.erb create mode 100644 benchmarks/blog/app/views/articles/show.json.jbuilder create mode 100644 benchmarks/blog/app/views/comments/_comment.html.erb create mode 100644 benchmarks/blog/app/views/layouts/application.html.erb create mode 100644 benchmarks/blog/benchmark.rb create mode 100755 benchmarks/blog/bin/rails create mode 100755 benchmarks/blog/bin/rake create mode 100644 benchmarks/blog/config.ru create mode 100644 benchmarks/blog/config/application.rb create mode 100644 benchmarks/blog/config/boot.rb create mode 100644 benchmarks/blog/config/cable.yml create mode 100644 benchmarks/blog/config/cache.yml create mode 100644 benchmarks/blog/config/database.yml create mode 100644 benchmarks/blog/config/environment.rb create mode 100644 benchmarks/blog/config/environments/production.rb create mode 100644 benchmarks/blog/config/importmap.rb create mode 100644 benchmarks/blog/config/initializers/assets.rb create mode 100644 benchmarks/blog/config/initializers/content_security_policy.rb create mode 100644 benchmarks/blog/config/initializers/filter_parameter_logging.rb create mode 100644 benchmarks/blog/config/initializers/inflections.rb create mode 100644 benchmarks/blog/config/locales/en.yml create mode 100644 benchmarks/blog/config/queue.yml create mode 100644 benchmarks/blog/config/routes.rb create mode 100644 benchmarks/blog/config/storage.yml create mode 100644 benchmarks/blog/db/cable_schema.rb create mode 100644 benchmarks/blog/db/cache_schema.rb create mode 100644 benchmarks/blog/db/queue_schema.rb create mode 100644 benchmarks/blog/db/schema.rb create mode 100644 benchmarks/blog/db/seeds.rb create mode 100644 benchmarks/blog/storage/.keep diff --git a/benchmarks.yml b/benchmarks.yml index 7acd18f3..3d884511 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -74,6 +74,8 @@ addressable-to-s: desc: addressable URI to string conversion binarytrees: desc: binarytrees from the Computer Language Benchmarks Game. +blog: + desc: blog is Sam Ruby's create-blog app on Rails 8.1 with the rails new defaults, reading, creating, updating and deleting articles and comments with validations and Turbo broadcasts, and rolling back each iteration. blurhash: desc: blurhash (blurred preview image) calculation ractor: true diff --git a/benchmarks/blog/.gitignore b/benchmarks/blog/.gitignore new file mode 100644 index 00000000..b1c36be7 --- /dev/null +++ b/benchmarks/blog/.gitignore @@ -0,0 +1,40 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# Temporary files generated by your text editor or operating system +# belong in git's global ignore instead: +# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +/public/assets + +# Ignore key files for decrypting credentials and more. +/config/*.key + + +/app/assets/builds/* +!/app/assets/builds/.keep +# Checked in so the benchmark needs no Tailwind build step. +!/app/assets/builds/tailwind.css diff --git a/benchmarks/blog/Gemfile b/benchmarks/blog/Gemfile new file mode 100644 index 00000000..74c464e7 --- /dev/null +++ b/benchmarks/blog/Gemfile @@ -0,0 +1,24 @@ +source "https://rubygems.org" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 8.1.4", ">= 8.1.4.1" +# The modern asset pipeline for Rails [https://github.com/rails/propshaft] +gem "propshaft" +# Use sqlite3 as the database for Active Record +gem "sqlite3", ">= 2.1" +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem "importmap-rails" +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem "turbo-rails" +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem "stimulus-rails" +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem "jbuilder" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ windows jruby ] + +# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable +gem "solid_cache" +gem "solid_queue" +gem "solid_cable" diff --git a/benchmarks/blog/Gemfile.lock b/benchmarks/blog/Gemfile.lock new file mode 100644 index 00000000..ada803d5 --- /dev/null +++ b/benchmarks/blog/Gemfile.lock @@ -0,0 +1,341 @@ +GEM + remote: https://rubygems.org/ + specs: + action_text-trix (2.1.19) + railties + actioncable (8.1.4.1) + actionpack (= 8.1.4.1) + activesupport (= 8.1.4.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.1.4.1) + actionpack (= 8.1.4.1) + activejob (= 8.1.4.1) + activerecord (= 8.1.4.1) + activestorage (= 8.1.4.1) + activesupport (= 8.1.4.1) + mail (>= 2.8.0) + actionmailer (8.1.4.1) + actionpack (= 8.1.4.1) + actionview (= 8.1.4.1) + activejob (= 8.1.4.1) + activesupport (= 8.1.4.1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.1.4.1) + actionview (= 8.1.4.1) + activesupport (= 8.1.4.1) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.1.4.1) + action_text-trix (~> 2.1.15) + actionpack (= 8.1.4.1) + activerecord (= 8.1.4.1) + activestorage (= 8.1.4.1) + activesupport (= 8.1.4.1) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.1.4.1) + activesupport (= 8.1.4.1) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6, >= 1.7.2) + activejob (8.1.4.1) + activesupport (= 8.1.4.1) + globalid (>= 0.3.6) + activemodel (8.1.4.1) + activesupport (= 8.1.4.1) + activerecord (8.1.4.1) + activemodel (= 8.1.4.1) + activesupport (= 8.1.4.1) + timeout (>= 0.4.0) + activestorage (8.1.4.1) + actionpack (= 8.1.4.1) + activejob (= 8.1.4.1) + activerecord (= 8.1.4.1) + activesupport (= 8.1.4.1) + marcel (~> 1.0) + activesupport (8.1.4.1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + json + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + base64 (0.3.0) + bigdecimal (4.1.3) + builder (3.3.0) + concurrent-ruby (1.3.8) + connection_pool (3.0.2) + crass (1.0.8) + date (3.6.0) + drb (2.2.3) + erb (6.0.7) + erubi (1.13.1) + et-orbi (1.4.2) + tzinfo + fugit (1.14.0) + et-orbi (~> 1.4) + raabro (~> 1.4) + globalid (1.4.0) + activesupport (>= 6.1) + i18n (1.15.2) + concurrent-ruby (~> 1.0) + importmap-rails (2.2.3) + actionpack (>= 6.0.0) + activesupport (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.9.5) + irb (1.18.0) + pp (>= 0.6.0) + prism (>= 1.3.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.15.1) + actionview (>= 7.0.0) + activesupport (>= 7.0.0) + json (3.1.0) + logger (1.7.0) + loofah (2.25.3) + crass (~> 1.0.2) + nokogiri (>= 1.19.5) + mail (2.9.1) + logger + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.2.1) + mini_mime (1.1.5) + mini_portile2 (2.8.9) + minitest (6.0.6) + drb (~> 2.0) + prism (~> 1.5) + net-imap (0.6.8) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.4.0) + timeout + net-smtp (0.5.2) + net-protocol + nio4r (2.7.5) + nokogiri (1.19.7) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + nokogiri (1.19.7-x86_64-linux-gnu) + racc (~> 1.4) + pp (0.6.4) + prettyprint + prettyprint (0.2.1) + prism (1.9.0) + propshaft (1.3.2) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + raabro (1.5.0) + racc (1.8.1) + rack (3.2.8) + rack-session (2.1.2) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.3.0) + rack (>= 1.3) + rackup (2.3.1) + rack (>= 3) + rails (8.1.4.1) + actioncable (= 8.1.4.1) + actionmailbox (= 8.1.4.1) + actionmailer (= 8.1.4.1) + actionpack (= 8.1.4.1) + actiontext (= 8.1.4.1) + actionview (= 8.1.4.1) + activejob (= 8.1.4.1) + activemodel (= 8.1.4.1) + activerecord (= 8.1.4.1) + activestorage (= 8.1.4.1) + activesupport (= 8.1.4.1) + bundler (>= 1.15.0) + railties (= 8.1.4.1) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.7.2) + loofah (~> 2.25, >= 2.25.3) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.1.4.1) + actionpack (= 8.1.4.1) + activesupport (= 8.1.4.1) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.4.2) + rbs (4.2.0) + logger + prism (>= 1.6.0) + tsort + rdoc (8.1.0) + erb + prism (>= 1.6.0) + rbs (>= 4.0.0) + tsort + reline (0.7.0) + io-console (~> 0.5) + securerandom (0.4.1) + solid_cable (4.1.0) + actioncable (>= 7.2) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) + solid_cache (1.0.10) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) + solid_queue (1.7.2) + activejob (>= 7.1) + activerecord (>= 7.1) + concurrent-ruby (>= 1.3.1) + fugit (~> 1.11) + railties (>= 7.1) + thor (>= 1.3.1) + sqlite3 (2.10.2) + mini_portile2 (~> 2.8.0) + sqlite3 (2.10.2-x86_64-linux-gnu) + stimulus-rails (1.3.4) + railties (>= 6.0.0) + thor (1.5.0) + timeout (0.6.1) + tsort (0.2.0) + turbo-rails (2.0.23) + actionpack (>= 7.1.0) + railties (>= 7.1.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uri (1.1.2) + useragent (0.16.11) + websocket-driver (0.8.2) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.8.3) + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + importmap-rails + jbuilder + propshaft + rails (~> 8.1.4, >= 8.1.4.1) + solid_cable + solid_cache + solid_queue + sqlite3 (>= 2.1) + stimulus-rails + turbo-rails + tzinfo-data + +CHECKSUMS + action_text-trix (2.1.19) sha256=7012f59421009cf284aa651294896414d653a61a2417c9b8714c8476d2f74009 + actioncable (8.1.4.1) sha256=007670f7297973e94809e9f32a56624a7aa60b6e9d6696cd078064ce86d1c7fc + actionmailbox (8.1.4.1) sha256=18b43dd842bf3a3e31b8e38b7917c21e48c128fc8b263c893481cc66ee1a8f78 + actionmailer (8.1.4.1) sha256=a7b71dedf744e48dd6751e97350634edce9a2f7beeceac332dcccb91729ad066 + actionpack (8.1.4.1) sha256=8c6f2e7cbd2653ef0539bde1ff20eb3e2e264e366affe56f0ba7f06d3670cb4b + actiontext (8.1.4.1) sha256=fb59611dc16e2b6bbfcec66793acfae6cdd64b1e35ef3f9175424f31e62c38da + actionview (8.1.4.1) sha256=d25b4d9cf8d0c0195ffcfe8b2cf3fcbe6fea54fd7c17f1a9cb8182881463f12b + activejob (8.1.4.1) sha256=82c4c9311ea1016d5f7f134a0c5f9b6527cad5a6237f5f3f60aa17984ef36229 + activemodel (8.1.4.1) sha256=063caf105372fbc98b2d789e4be23de63ac5c043f7d9330f04e2caddb7012805 + activerecord (8.1.4.1) sha256=bd65599ca0b5d210937f835d42c7aff69d271741c75aab022730be6cbce67e87 + activestorage (8.1.4.1) sha256=0f4e2f114f3584723a80a2c089aacc6170e765a0b2c385c9782e26ed78f05c66 + activesupport (8.1.4.1) sha256=16ac4f341ca65c85a1fcdb8ac73f68891aae9e3c4a6f9c3a27daed8b00017ed7 + base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b + bigdecimal (4.1.3) sha256=61ebe1e5e559bdc3cc6f2c0ee7f427321fc838f59611c294356eb04d6e21cf66 + builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f + bundler (4.0.20) sha256=7978a8ac648767f5e635bc522445b79e80a52b907a39a36c2d8085ed6bc762ae + concurrent-ruby (1.3.8) sha256=b2f1be836e968ccc78ccfce277ea79c72a88633f22306782c16ff23fb415d1e1 + connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a + crass (1.0.8) sha256=7a0145c7a2c59f8e7923b3a69ce819c444823a00a5127d805298fea13be24efe + date (3.6.0) sha256=18ac945c4e24ebd93534f8eab8c2fd8c5604b3e977105b3798d62a1e8d27b580 + drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373 + erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92 + erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9 + et-orbi (1.4.2) sha256=bb555dae668419cb24caa2a293a170e58be6d4df1e017c51f5030bdc133cd20c + fugit (1.14.0) sha256=e311a9cc85a54bb67649df45060e721282a1e2c8ebad40e41874a3a7d576f37e + globalid (1.4.0) sha256=037f12fbf1d9d7a014d501c2d5c77356fd4ddd96d7a7991d6700bba96706f427 + i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5 + importmap-rails (2.2.3) sha256=7101be2a4dc97cf1558fb8f573a718404c5f6bcfe94f304bf1f39e444feeb16a + io-console (0.9.5) sha256=83dd9bbf4c4680416629245b39cd4212eb5f4d9a4ea91804870c1f6b846414d5 + irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3 + jbuilder (2.15.1) sha256=2430bec28fb0cebacb5875b1009cf9d8bc3c303ccb810c4c8b062a4b51457637 + json (3.1.0) sha256=3ce7ccf8fde58960177a3a756c31f292a4c1e1dedee884547096a5b0604e3bd8 + logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203 + loofah (2.25.3) sha256=545f14eef0cc2a7de80df560530d593232b7c07e515c5c4e37532d9cb5b0185c + mail (2.9.1) sha256=06574eca475253d6c18145dd70af80d0eb970182d55053497c5f4d797ea160e8 + marcel (1.2.1) sha256=1678e9360e32f9eafa917c80029e2f6d10b2715c66a4b87b6d0da9b9cd1f859f + mini_mime (1.1.5) sha256=8681b7e2e4215f2a159f9400b5816d85e9d8c6c6b491e96a12797e798f8bccef + mini_portile2 (2.8.9) sha256=0cd7c7f824e010c072e33f68bc02d85a00aeb6fce05bb4819c03dfd3c140c289 + minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1 + net-imap (0.6.8) sha256=eb30bb62227b64a3af6b518b04b2375113d69f68f15de59b0193b07d98acf6d9 + net-pop (0.1.2) sha256=848b4e982013c15b2f0382792268763b748cce91c9e91e36b0f27ed26420dff3 + net-protocol (0.4.0) sha256=f9f90c8c6f64794a45160bf422177a336db12809de3beeeaa26b88fcd2e8c853 + net-smtp (0.5.2) sha256=35103cc04d6b2d94632f9928ede07483c24b70b9c0db1f231fea43909b678f3c + nio4r (2.7.5) sha256=6c90168e48fb5f8e768419c93abb94ba2b892a1d0602cb06eef16d8b7df1dca1 + nokogiri (1.19.7) sha256=abe94507c54cb18f872777b16bdca4aad32b1abdc4c52fe843f1c80fbdf992b8 + nokogiri (1.19.7-x86_64-linux-gnu) sha256=25865ccb462f714e712fdf8906fde07849cb6704a808e3d629d75baa5af5dd3b + pp (0.6.4) sha256=dfcb0fce700c41456265922884f9fe195d7fbb0674a3578e6c0f69588e82b570 + prettyprint (0.2.1) sha256=d555d57ea6d7cf001d4774b693546a6bd88bec1e778ddffb5c60b68ceec4b7d4 + prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85 + propshaft (1.3.2) sha256=1d56a3e56a92c21bfc29caf07406b5386b00d4c47ddf357cf989a5a234b1389e + raabro (1.5.0) sha256=3f998a7bc84f9c84df3ab580634d2e0a5bda4f0841168d56035f529c9877440a + racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f + rack (3.2.8) sha256=1fecc85e463ebc7a2a945fff829ffcd549babeb1556384796fad946c28dc4ec7 + rack-session (2.1.2) sha256=595434f8c0c3473ae7d7ac56ecda6cc6dfd9d37c0b2b5255330aa1576967ffe8 + rack-test (2.3.0) sha256=b118d177cc002c572fc1b6fd8d19c9ed5881a36e8d6f689f9e618f9f861241e8 + rackup (2.3.1) sha256=6c79c26753778e90983761d677a48937ee3192b3ffef6bc963c0950f94688868 + rails (8.1.4.1) sha256=365c3a0ad2713bd6e60628e5e826622d4ca8dee60b5a7e560e9b20844e9650bc + rails-dom-testing (2.3.0) sha256=8acc7953a7b911ca44588bf08737bc16719f431a1cc3091a292bca7317925c1d + rails-html-sanitizer (1.7.2) sha256=a21ef45b7a6639fc8e2282473c547514cb86ae271616162a946bf89148fa2424 + railties (8.1.4.1) sha256=ff2ef4b5a62cbc89811f88be11c776e2ed71b14dd012eae6a494d37994aa9782 + rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701 + rbs (4.2.0) sha256=51f7b886dcc05bc09e10b901daa6a81829f6adc03101d6ca9ea4aac6103e0674 + rdoc (8.1.0) sha256=befc37880a5cfd36dcb176c748b5fd5ee39dd3536a75e81824e4972ce230f60a + reline (0.7.0) sha256=5b012d8e55dbf9d450f12bde2cf7d15ff546ae80b3f8f3b30e570d431815583d + securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1 + solid_cable (4.1.0) sha256=828e3d509207b82b4f05f4e9c85f696994710679b52d511aa7f97ebd212d3226 + solid_cache (1.0.10) sha256=bc05a2fb3ac78a6f43cbb5946679cf9db67dd30d22939ededc385cb93e120d41 + solid_queue (1.7.2) sha256=a22685e1d2ee14ce7b4e5d4592c9d8e837951884c51555609dee58679ed03325 + sqlite3 (2.10.2) sha256=f1ea68cd3287f8a49f39a088ac9e4bd0ef4e7f394c3d4a60dd4c7e44b0566964 + sqlite3 (2.10.2-x86_64-linux-gnu) sha256=ca92731ab464df9cae503fa1a439a549e2724f6953c8c05a7769b59366e38f15 + stimulus-rails (1.3.4) sha256=765676ffa1f33af64ce026d26b48e8ffb2e0b94e0f50e9119e11d6107d67cb06 + thor (1.5.0) sha256=e3a9e55fe857e44859ce104a84675ab6e8cd59c650a49106a05f55f136425e73 + timeout (0.6.1) sha256=78f57368a7e7bbadec56971f78a3f5ecbcfb59b7fcbb0a3ed6ddc08a5094accb + tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f + turbo-rails (2.0.23) sha256=ee0d90733aafff056cf51ff11e803d65e43cae258cc55f6492020ec1f9f9315f + tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b + uri (1.1.2) sha256=89292e98eabbef6248b0a0ed5e7e398e152f83f17560023a6d94a7f492b169fb + useragent (0.16.11) sha256=700e6413ad4bb954bb63547fa098dddf7b0ebe75b40cc6f93b8d54255b173844 + websocket-driver (0.8.2) sha256=97c556b019bf3410b4961002ac501621e9322d3f8a7bc02161a09301cc4c4146 + websocket-extensions (0.1.5) sha256=1c6ba63092cda343eb53fc657110c71c754c56484aad42578495227d717a8241 + zeitwerk (2.8.3) sha256=2c85125a8467ce069e20123d1e709a08955c9d29c118c25b46b7b7fafdbb92e5 + +BUNDLED WITH + 4.0.20 diff --git a/benchmarks/blog/LICENSE b/benchmarks/blog/LICENSE new file mode 100644 index 00000000..0fcfffa0 --- /dev/null +++ b/benchmarks/blog/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Sam Ruby + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/benchmarks/blog/README.md b/benchmarks/blog/README.md new file mode 100644 index 00000000..21f59c0b --- /dev/null +++ b/benchmarks/blog/README.md @@ -0,0 +1,58 @@ +# Blog benchmark + +This is the app built by the +[`create-blog`](https://github.com/roundhouse-rb/roundhouse/blob/aa60799f53b36084c6311ffcda8f14e746eebf79/scripts/create-blog) +script from Sam Ruby's [Roundhouse](https://github.com/roundhouse-rb/roundhouse) (MIT or Apache-2.0, used here under +MIT, see [LICENSE](LICENSE)): +`rails new --css tailwind` plus Article and Comment scaffolds with comments nested under articles, validations, +Turbo broadcasts, jbuilder JSON and seeds. It runs the production defaults of `rails new`: SQLite, Solid Cache, +Solid Queue, Solid Cable, Propshaft, importmap, Turbo and Stimulus. + +It was generated with `RAILS_NEW_VERSION=8.1.4.1 scripts/create-blog blog`, then `bin/rails db:migrate` to write +`db/schema.rb`. Changes after that: + +- `config/master.key`, `config/credentials.yml.enc`, `.github/` and `.ruby-version` are removed; `benchmark.rb` sets + `SECRET_KEY_BASE`. +- `config/environments/production.rb` sets `config.yjit = false`, so ruby-bench decides which JIT runs. +- `app/assets/builds/tailwind.css` is built and checked in, so the benchmark runs no Tailwind build. `.gitignore` is + the one `rails new` writes without `--skip-git`, plus that file. +- Files that only deployment, development, tests or a web server use are removed: `.kamal/`, `config/deploy.yml`, + `bin/` except `rails` and `rake`, `public/`, `test/`, the development and test environments, `config/puma.rb`, + `config/recurring.yml`, `config/ci.rb`, `config/bundler-audit.yml`, `.rubocop.yml`, `Procfile.dev`, `db/migrate/` + (`db/schema.rb` creates the tables), the PWA views, the mailer and its layouts, `ApplicationJob`, the empty helpers, + and the `.keep` files in `lib/`, `script/`, `vendor/`, `log/`, `tmp/`, `app/assets/images/` and the `concerns/` + directories. Eager loading loaded the mailer, job and helpers at boot, but no request used them, and every response + is the same without them. +- The Gemfile keeps only the default group, without kamal, thruster, puma, bootsnap and tailwindcss-rails: the app + runs in-process, and the CSS is already built. `gem "image_processing"` is removed too: nothing here touches images, + and with it Active Storage loads libvips at boot when the host has it, so boot would depend on the machine. +- `Gemfile.lock` lists the `ruby` and `x86_64-linux` platforms, like the other benchmarks. +- This README and LICENSE. + +## What an iteration does + +`benchmark.rb` calls the app in-process with a fixed, seeded sequence of 200 visits: the index, article pages and +their JSON; creating, updating and deleting articles; adding and deleting comments; and a create that fails +validation with a 422. Each write first GETs the page with its form, submits that form's CSRF token the way a +browser does, and follows the redirect. Every response is checked for its status, and for a marker in the body or +the redirect's `Location`. + +Each iteration runs in one transaction per database (primary, cache, queue and cable) that is rolled back at the +end, as in Rails tests, so every iteration starts from the same rows and gets the same IDs. While the app runs, the +clock starts at 2026-07-01 12:00 UTC and advances one second per visit, so updates still write `updated_at`. + +Because the iteration's outer transaction is not joinable, each save runs as a savepoint, and its after-commit +callbacks run when the savepoint is released, as in Rails tests. They run in the same order relative to each write +as in production; what differs is SAVEPOINT/RELEASE in place of BEGIN IMMEDIATE/COMMIT. Nothing is ever committed, +so a real COMMIT and its WAL write are not measured. + +Turbo renders the immediate broadcasts in the request and Solid Cable inserts them; `benchmark.rb` makes that insert +synchronous instead of batching it on Solid Cable's writer thread, which also skips Solid Cable's random autotrim. +The later broadcasts are enqueued into Solid Queue, and no worker runs them. Each iteration checks the number of +Solid Cable messages and Solid Queue jobs it wrote. Solid Cache is configured but the app doesn't use the cache. +Assets aren't precompiled, so Propshaft resolves their digested paths from its load path rather than a manifest. + +An iteration holds write locks on the four SQLite files, so two processes can't run this benchmark from the same +directory at the same time. + +The app uses the `sqlite3` C extension, so like lobsters and shipit it doesn't run on JRuby. diff --git a/benchmarks/blog/Rakefile b/benchmarks/blog/Rakefile new file mode 100644 index 00000000..9a5ea738 --- /dev/null +++ b/benchmarks/blog/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/benchmarks/blog/app/assets/builds/.keep b/benchmarks/blog/app/assets/builds/.keep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/blog/app/assets/builds/tailwind.css b/benchmarks/blog/app/assets/builds/tailwind.css new file mode 100644 index 00000000..3f596d41 --- /dev/null +++ b/benchmarks/blog/app/assets/builds/tailwind.css @@ -0,0 +1,2 @@ +/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */ +@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-space-x-reverse:0;--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial}}}@layer theme{:root,:host{--font-sans:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-green-50:oklch(98.2% .018 155.826);--color-green-500:oklch(72.3% .219 149.579);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-white:#fff;--spacing:.25rem;--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-lg:1.125rem;--text-lg--line-height:calc(1.75 / 1.125);--text-xl:1.25rem;--text-xl--line-height:calc(1.75 / 1.25);--text-4xl:2.25rem;--text-4xl--line-height:calc(2.5 / 2.25);--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--radius-md:.375rem;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring:where(:not(iframe)){outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.collapse{visibility:collapse}.collapse\!{visibility:collapse!important}.invisible{visibility:hidden}.visible{visibility:visible}.absolute{position:absolute}.relative{position:relative}.static{position:static}.sticky{position:sticky}.isolate{isolation:isolate}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.mx-auto{margin-inline:auto}.my-4{margin-block:calc(var(--spacing) * 4)}.my-5{margin-block:calc(var(--spacing) * 5)}.my-8{margin-block:calc(var(--spacing) * 8)}.my-10{margin-block:calc(var(--spacing) * 10)}.mt-2{margin-top:calc(var(--spacing) * 2)}.mt-3{margin-top:calc(var(--spacing) * 3)}.mt-28{margin-top:calc(var(--spacing) * 28)}.mb-2{margin-bottom:calc(var(--spacing) * 2)}.mb-4{margin-bottom:calc(var(--spacing) * 4)}.mb-5{margin-bottom:calc(var(--spacing) * 5)}.mb-8{margin-bottom:calc(var(--spacing) * 8)}.ml-2{margin-left:calc(var(--spacing) * 2)}.ml-6{margin-left:calc(var(--spacing) * 6)}.block{display:block}.contents{display:contents}.flex{display:flex}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.table{display:table}.w-full{width:100%}.min-w-full{min-width:100%}.flex-grow{flex-grow:1}.transform{transform:var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,)}.cursor-pointer{cursor:pointer}.resize{resize:both}.list-disc{list-style-type:disc}.flex-col{flex-direction:column}.items-center{align-items:center}.justify-between{justify-content:space-between}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-4>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 4) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 4) * calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 5) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 5) * calc(1 - var(--tw-space-y-reverse)))}:where(.space-x-2>:not(:last-child)){--tw-space-x-reverse:0;margin-inline-start:calc(calc(var(--spacing) * 2) * var(--tw-space-x-reverse));margin-inline-end:calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-x-reverse)))}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px * var(--tw-divide-y-reverse));border-bottom-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-gray-200>:not(:last-child)){border-color:var(--color-gray-200)}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-400{border-color:var(--color-gray-400)}.border-red-400{border-color:var(--color-red-400)}.bg-blue-600{background-color:var(--color-blue-600)}.bg-gray-50{background-color:var(--color-gray-50)}.bg-gray-100{background-color:var(--color-gray-100)}.bg-green-50{background-color:var(--color-green-50)}.bg-red-50{background-color:var(--color-red-50)}.bg-red-600{background-color:var(--color-red-600)}.p-2{padding:calc(var(--spacing) * 2)}.p-4{padding:calc(var(--spacing) * 4)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-3\.5{padding-inline:calc(var(--spacing) * 3.5)}.px-4{padding-inline:calc(var(--spacing) * 4)}.px-5{padding-inline:calc(var(--spacing) * 5)}.py-2{padding-block:calc(var(--spacing) * 2)}.py-2\.5{padding-block:calc(var(--spacing) * 2.5)}.pb-5{padding-bottom:calc(var(--spacing) * 5)}.text-center{text-align:center}.text-4xl{font-size:var(--text-4xl);line-height:var(--tw-leading,var(--text-4xl--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-blue-600{color:var(--color-blue-600)}.text-gray-500{color:var(--color-gray-500)}.text-gray-700{color:var(--color-gray-700)}.text-green-500{color:var(--color-green-500)}.text-red-500{color:var(--color-red-500)}.text-red-600{color:var(--color-red-600)}.text-white{color:var(--color-white)}.lowercase{text-transform:lowercase}.uppercase{text-transform:uppercase}.italic{font-style:italic}.shadow,.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.blur{--tw-blur:blur(8px);filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.invert{--tw-invert:invert(100%);filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.filter{filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}@media (hover:hover){.hover\:bg-blue-500:hover{background-color:var(--color-blue-500)}.hover\:bg-gray-50:hover{background-color:var(--color-gray-50)}.hover\:bg-red-500:hover{background-color:var(--color-red-500)}.hover\:underline:hover{text-decoration-line:underline}}.focus\:outline-blue-600:focus{outline-color:var(--color-blue-600)}.focus\:outline-red-600:focus{outline-color:var(--color-red-600)}@media (min-width:40rem){.sm\:mt-0{margin-top:0}.sm\:ml-2{margin-left:calc(var(--spacing) * 2)}.sm\:inline-block{display:inline-block}.sm\:w-auto{width:auto}.sm\:flex-row{flex-direction:row}.sm\:pb-0{padding-bottom:0}}@media (min-width:48rem){.md\:w-2\/3{width:66.6667%}}}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-space-x-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false} \ No newline at end of file diff --git a/benchmarks/blog/app/assets/stylesheets/application.css b/benchmarks/blog/app/assets/stylesheets/application.css new file mode 100644 index 00000000..fe93333c --- /dev/null +++ b/benchmarks/blog/app/assets/stylesheets/application.css @@ -0,0 +1,10 @@ +/* + * This is a manifest file that'll be compiled into application.css. + * + * With Propshaft, assets are served efficiently without preprocessing steps. You can still include + * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard + * cascading order, meaning styles declared later in the document or manifest will override earlier ones, + * depending on specificity. + * + * Consider organizing styles into separate files for maintainability. + */ diff --git a/benchmarks/blog/app/assets/tailwind/application.css b/benchmarks/blog/app/assets/tailwind/application.css new file mode 100644 index 00000000..f1d8c73c --- /dev/null +++ b/benchmarks/blog/app/assets/tailwind/application.css @@ -0,0 +1 @@ +@import "tailwindcss"; diff --git a/benchmarks/blog/app/controllers/application_controller.rb b/benchmarks/blog/app/controllers/application_controller.rb new file mode 100644 index 00000000..c3537563 --- /dev/null +++ b/benchmarks/blog/app/controllers/application_controller.rb @@ -0,0 +1,7 @@ +class ApplicationController < ActionController::Base + # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. + allow_browser versions: :modern + + # Changes to the importmap will invalidate the etag for HTML responses + stale_when_importmap_changes +end diff --git a/benchmarks/blog/app/controllers/articles_controller.rb b/benchmarks/blog/app/controllers/articles_controller.rb new file mode 100644 index 00000000..c0404af0 --- /dev/null +++ b/benchmarks/blog/app/controllers/articles_controller.rb @@ -0,0 +1,70 @@ +class ArticlesController < ApplicationController + before_action :set_article, only: %i[ show edit update destroy ] + + # GET /articles or /articles.json + def index + @articles = Article.includes(:comments).order(created_at: :desc) + end + + # GET /articles/1 or /articles/1.json + def show + end + + # GET /articles/new + def new + @article = Article.new + end + + # GET /articles/1/edit + def edit + end + + # POST /articles or /articles.json + def create + @article = Article.new(article_params) + + respond_to do |format| + if @article.save + format.html { redirect_to @article, notice: "Article was successfully created." } + format.json { render :show, status: :created, location: @article } + else + format.html { render :new, status: :unprocessable_content } + format.json { render json: @article.errors, status: :unprocessable_content } + end + end + end + + # PATCH/PUT /articles/1 or /articles/1.json + def update + respond_to do |format| + if @article.update(article_params) + format.html { redirect_to @article, notice: "Article was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @article } + else + format.html { render :edit, status: :unprocessable_content } + format.json { render json: @article.errors, status: :unprocessable_content } + end + end + end + + # DELETE /articles/1 or /articles/1.json + def destroy + @article.destroy! + + respond_to do |format| + format.html { redirect_to articles_path, notice: "Article was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_article + @article = Article.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def article_params + params.expect(article: [ :title, :body ]) + end +end diff --git a/benchmarks/blog/app/controllers/comments_controller.rb b/benchmarks/blog/app/controllers/comments_controller.rb new file mode 100644 index 00000000..598c4235 --- /dev/null +++ b/benchmarks/blog/app/controllers/comments_controller.rb @@ -0,0 +1,28 @@ +class CommentsController < ApplicationController + before_action :set_article + + def create + @comment = @article.comments.build(comment_params) + if @comment.save + redirect_to @article, notice: "Comment was successfully created." + else + redirect_to @article, alert: "Could not create comment." + end + end + + def destroy + @comment = @article.comments.find(params.expect(:id)) + @comment.destroy + redirect_to @article, notice: "Comment was successfully deleted." + end + + private + + def set_article + @article = Article.find(params.expect(:article_id)) + end + + def comment_params + params.expect(comment: [ :commenter, :body ]) + end +end diff --git a/benchmarks/blog/app/javascript/application.js b/benchmarks/blog/app/javascript/application.js new file mode 100644 index 00000000..0d7b4940 --- /dev/null +++ b/benchmarks/blog/app/javascript/application.js @@ -0,0 +1,3 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" +import "controllers" diff --git a/benchmarks/blog/app/javascript/controllers/application.js b/benchmarks/blog/app/javascript/controllers/application.js new file mode 100644 index 00000000..1213e85c --- /dev/null +++ b/benchmarks/blog/app/javascript/controllers/application.js @@ -0,0 +1,9 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.debug = false +window.Stimulus = application + +export { application } diff --git a/benchmarks/blog/app/javascript/controllers/hello_controller.js b/benchmarks/blog/app/javascript/controllers/hello_controller.js new file mode 100644 index 00000000..5975c078 --- /dev/null +++ b/benchmarks/blog/app/javascript/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.textContent = "Hello World!" + } +} diff --git a/benchmarks/blog/app/javascript/controllers/index.js b/benchmarks/blog/app/javascript/controllers/index.js new file mode 100644 index 00000000..1156bf83 --- /dev/null +++ b/benchmarks/blog/app/javascript/controllers/index.js @@ -0,0 +1,4 @@ +// Import and register all your controllers from the importmap via controllers/**/*_controller +import { application } from "controllers/application" +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) diff --git a/benchmarks/blog/app/models/application_record.rb b/benchmarks/blog/app/models/application_record.rb new file mode 100644 index 00000000..b63caeb8 --- /dev/null +++ b/benchmarks/blog/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/benchmarks/blog/app/models/article.rb b/benchmarks/blog/app/models/article.rb new file mode 100644 index 00000000..549627e6 --- /dev/null +++ b/benchmarks/blog/app/models/article.rb @@ -0,0 +1,10 @@ +class Article < ApplicationRecord + has_many :comments, dependent: :destroy + + # Broadcast article changes to index page subscribers + # Lambda receives the record being broadcast + broadcasts_to ->(_article) { "articles" }, inserts_by: :prepend + + validates :title, presence: true + validates :body, presence: true, length: { minimum: 10 } +end diff --git a/benchmarks/blog/app/models/comment.rb b/benchmarks/blog/app/models/comment.rb new file mode 100644 index 00000000..57c280de --- /dev/null +++ b/benchmarks/blog/app/models/comment.rb @@ -0,0 +1,15 @@ +class Comment < ApplicationRecord + belongs_to :article + + validates :commenter, presence: true + validates :body, presence: true + + # Broadcast comment changes to article show page subscribers + # Lambda receives the record being broadcast + broadcasts_to ->(comment) { "article_#{comment.article_id}_comments" }, target: "comments" + + # Also update article on index when comments change (for comment count) + # rescue nil: during seeding, URL helpers aren't available but no one is listening anyway + after_create_commit { article.broadcast_replace_to("articles") rescue nil } + after_destroy_commit { article.broadcast_replace_to("articles") rescue nil } +end diff --git a/benchmarks/blog/app/views/articles/_article.html.erb b/benchmarks/blog/app/views/articles/_article.html.erb new file mode 100644 index 00000000..1bf04632 --- /dev/null +++ b/benchmarks/blog/app/views/articles/_article.html.erb @@ -0,0 +1,16 @@ +
+
+

+ <%= link_to article.title, article, class: "text-blue-600 hover:underline" %> + + (<%= pluralize(article.comments.size, "comment") %>) + +

+

<%= truncate(article.body, length: 100) %>

+
+
+ <%= link_to "Show", article, class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= link_to "Edit", edit_article_path(article), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= button_to "Destroy", article, method: :delete, class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %> +
+
diff --git a/benchmarks/blog/app/views/articles/_article.json.jbuilder b/benchmarks/blog/app/views/articles/_article.json.jbuilder new file mode 100644 index 00000000..064457b2 --- /dev/null +++ b/benchmarks/blog/app/views/articles/_article.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! article, :id, :title, :body, :created_at, :updated_at +json.url article_url(article, format: :json) diff --git a/benchmarks/blog/app/views/articles/_form.html.erb b/benchmarks/blog/app/views/articles/_form.html.erb new file mode 100644 index 00000000..c245e0a9 --- /dev/null +++ b/benchmarks/blog/app/views/articles/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: article, class: "contents") do |form| %> + <% if article.errors.any? %> +
+

<%= pluralize(article.errors.count, "error") %> prohibited this article from being saved:

+ +
    + <% article.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :title %> + <%= form.text_field :title, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": article.errors[:title].none?, "border-red-400 focus:outline-red-600": article.errors[:title].any?}] %> +
+ +
+ <%= form.label :body %> + <%= form.textarea :body, rows: 4, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": article.errors[:body].none?, "border-red-400 focus:outline-red-600": article.errors[:body].any?}] %> +
+ +
+ <%= form.submit class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %> +
+<% end %> diff --git a/benchmarks/blog/app/views/articles/edit.html.erb b/benchmarks/blog/app/views/articles/edit.html.erb new file mode 100644 index 00000000..03c10894 --- /dev/null +++ b/benchmarks/blog/app/views/articles/edit.html.erb @@ -0,0 +1,10 @@ +<% content_for :title, "Editing article" %> + +
+

Editing article

+ + <%= render "form", article: @article %> + + <%= link_to "Show this article", @article, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= link_to "Back to articles", articles_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> +
diff --git a/benchmarks/blog/app/views/articles/index.html.erb b/benchmarks/blog/app/views/articles/index.html.erb new file mode 100644 index 00000000..5b2d5417 --- /dev/null +++ b/benchmarks/blog/app/views/articles/index.html.erb @@ -0,0 +1,31 @@ +<%= turbo_stream_from "articles" %> + +<% content_for :title, "Articles" %> + +<%# The bare statement spelling of a turbo Drive directive (campfire's + sessions/new shape). `exempts_page_from_cache` and not + `page_requires_reload`, which is a NAVIGATION change: Turbo + full-reloads a page carrying it, and on a page with a form that + drops the 422 re-render the validation e2e asserts on. Live Rails + does the same — the directive works, it just wants a page without + a form. %> +<% turbo_exempts_page_from_cache %> + +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + +
+

Articles

+ <%= link_to "New article", new_article_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %> +
+ +
+ <% if @articles.any? %> + <%= render @articles %> + <% else %> +

No articles found.

+ <% end %> +
+
diff --git a/benchmarks/blog/app/views/articles/index.json.jbuilder b/benchmarks/blog/app/views/articles/index.json.jbuilder new file mode 100644 index 00000000..09a21f39 --- /dev/null +++ b/benchmarks/blog/app/views/articles/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @articles, partial: "articles/article", as: :article diff --git a/benchmarks/blog/app/views/articles/new.html.erb b/benchmarks/blog/app/views/articles/new.html.erb new file mode 100644 index 00000000..3fa2f6be --- /dev/null +++ b/benchmarks/blog/app/views/articles/new.html.erb @@ -0,0 +1,9 @@ +<% content_for :title, "New article" %> + +
+

New article

+ + <%= render "form", article: @article %> + + <%= link_to "Back to articles", articles_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> +
diff --git a/benchmarks/blog/app/views/articles/show.html.erb b/benchmarks/blog/app/views/articles/show.html.erb new file mode 100644 index 00000000..44751d67 --- /dev/null +++ b/benchmarks/blog/app/views/articles/show.html.erb @@ -0,0 +1,52 @@ +<% content_for :title, "Showing article" %> + +<%# A turbo Drive directive INSIDE a content_for block for the same + slot — campfire's rooms/show shape, and the reason `content_for` + has to APPEND: `provide` deposits the directive first, this + block's markup follows it, and an overwriting store keeps only + one of them. %> +<% content_for :head do %> + <%= turbo_exempts_page_from_preview %> + +<% end %> + +
+ <% if notice.present? %> +

<%= notice %>

+ <% end %> + +

<%= @article.title %>

+ +
+

<%= @article.body %>

+
+ + <%= link_to "Edit this article", edit_article_path(@article), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= link_to "Back to articles", articles_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> + <%= button_to "Destroy this article", @article, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", class: "w-full rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %> +
+ +
+ +

Comments

+ +<%# Subscribe to real-time comment updates for this article %> +<%= turbo_stream_from "article_#{@article.id}_comments" %> + +
+ <%= render @article.comments %> +
+ +

Add a Comment

+ +<%= form_with model: [@article, Comment.new], class: "space-y-4" do |form| %> +
+ <%= form.label :commenter, class: "block font-medium" %> + <%= form.text_field :commenter, class: "block w-full border rounded p-2" %> +
+
+ <%= form.label :body, class: "block font-medium" %> + <%= form.text_area :body, rows: 3, class: "block w-full border rounded p-2" %> +
+ <%= form.submit "Add Comment", class: "bg-blue-600 text-white px-4 py-2 rounded" %> +<% end %> diff --git a/benchmarks/blog/app/views/articles/show.json.jbuilder b/benchmarks/blog/app/views/articles/show.json.jbuilder new file mode 100644 index 00000000..dd1fbb4c --- /dev/null +++ b/benchmarks/blog/app/views/articles/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "articles/article", article: @article diff --git a/benchmarks/blog/app/views/comments/_comment.html.erb b/benchmarks/blog/app/views/comments/_comment.html.erb new file mode 100644 index 00000000..665aa460 --- /dev/null +++ b/benchmarks/blog/app/views/comments/_comment.html.erb @@ -0,0 +1,7 @@ +
+

<%= comment.commenter %>

+

<%= comment.body %>

+ <%= button_to "Delete", [comment.article, comment], method: :delete, + class: "text-red-600 text-sm mt-2", + data: { turbo_confirm: "Are you sure?" } %> +
diff --git a/benchmarks/blog/app/views/layouts/application.html.erb b/benchmarks/blog/app/views/layouts/application.html.erb new file mode 100644 index 00000000..f1222a9d --- /dev/null +++ b/benchmarks/blog/app/views/layouts/application.html.erb @@ -0,0 +1,31 @@ + + + + <%= content_for(:title) || "Blog" %> + + + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> + <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> + + + + + + <%# Includes all stylesheet files in app/assets/stylesheets %> + <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> + + + +
+ <%= yield %> +
+ + diff --git a/benchmarks/blog/benchmark.rb b/benchmarks/blog/benchmark.rb new file mode 100644 index 00000000..4d4cfd53 --- /dev/null +++ b/benchmarks/blog/benchmark.rb @@ -0,0 +1,203 @@ +require_relative '../../lib/harness/loader' + +ENV['RAILS_ENV'] ||= 'production' +ENV['RAILS_LOG_LEVEL'] ||= 'error' # Production logs every request to STDOUT at info. +ENV['SECRET_KEY_BASE'] ||= 'in general secret should not be in the git repo but this is a benchmark' + +Dir.chdir __dir__ +use_gemfile extra_setup_cmd: "ruby bin/rails db:prepare" # Windows cannot run bin/rails by its shebang + +# A fixed clock keeps the work independent of the date; it advances per visit so updated_at changes. +START_TIME = Time.utc(2026, 7, 1, 12, 0, 0, 123456.789r).getlocal.freeze +REAL_NOW = Time.method(:now) +def Time.now = $now ? $now.dup : REAL_NOW.call + +class Browser + USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36" + FORM_ACCEPT = "text/vnd.turbo-stream.html, text/html, application/xhtml+xml" # what Turbo sends on form submissions + + attr_accessor :cookie + + def initialize(app) + @app = app + end + + def get(path) + request(path, method: "GET") + end + + def submit(page, action, params = {}, method: nil) + token = page[/
]*action="#{Regexp.escape(action)}"[^>]*>.*?name="authenticity_token" value="([^"]+)"/m, 1] + raise "No form for #{action}" unless token + params = params.merge(authenticity_token: token) + params[:_method] = method if method + request(action, method: "POST", params: params, "HTTP_ACCEPT" => FORM_ACCEPT) + end + + private + + def request(path, method:, params: nil, **headers) + env = Rack::MockRequest.env_for("http://localhost#{path}", method: method, params: params, + "HTTP_USER_AGENT" => USER_AGENT, **headers) + env["HTTP_COOKIE"] = cookie if cookie + status, response_headers, body = @app.call(env) + self.cookie = response_headers["set-cookie"].split(";", 2).first if response_headers["set-cookie"] + text = +"" + body.each { |part| text << part } + body.close if body.respond_to?(:close) # Response might be a Rack::BodyProxy and MUST be closed. + [status, response_headers["location"], text] + end +end + +def expect(response, status, *markers, location: nil) + actual_status, actual_location, body = response + if actual_status != status || (location && actual_location != "http://localhost#{location}") || + (missing = markers.find { |marker| marker.is_a?(Regexp) ? body !~ marker : !body.include?(marker) }) + raise "Expected #{status} #{location} #{missing.inspect}, got #{actual_status} #{actual_location}: #{body[0, 300]}" + end + body +end + +begin + $now = START_TIME + require_relative 'config/environment' + + app = Rails.application + + # Insert broadcasts in the request, inside the iteration's transaction, not from Solid Cable's writer thread. + ActionCable.server.pubsub.instance_variable_set(:@broadcaster, SolidCable::Message) + + # IDs are predictable because every iteration rolls back sqlite_sequence too. + sequence = ->(table) { ActiveRecord::Base.with_connection { _1.select_value("SELECT seq FROM sqlite_sequence WHERE name = '#{table}'") }.to_i } + next_article_id = sequence.("articles") + 1 + next_comment_id = sequence.("comments") + 1 + articles = Article.order(:id).to_h { |article| [article.id, { title: article.title, comments: article.comments.ids }] } + + rng = Random.new(0x1be52551fc152997) + bodies = [ + "Turbo Streams deliver page changes as fragments of HTML wrapped in turbo-stream elements.", + "SQLite is a good default for small apps: one file, no server, and WAL mode keeps readers off the writer's back.", + "Validations run before every save, and callbacks run around it. Both are plain Ruby, so both are worth measuring.", + ] + weights = { show: 20, index: 10, show_json: 8, index_json: 4, create_article: 12, create_comment: 20, + update_article: 8, invalid_article: 6, destroy_comment: 6, destroy_article: 6 } + kinds = weights.flat_map { |kind, weight| [kind] * weight } + visits = [] + # Seeding enqueues broadcast jobs too, so count from what's there. + expected_messages = SolidCable::Message.count + expected_jobs = SolidQueue::Job.count + until visits.size == 200 + kind = kinds.sample(random: rng) + id = articles.keys.sample(random: rng) + case kind + when :create_article + title = "Article #{next_article_id}" + visits << [kind, next_article_id, title, bodies.sample(random: rng)] + articles[next_article_id] = { title: title, comments: [] } + next_article_id += 1 + expected_jobs += 1 # broadcasts_to prepends it on the index later + when :update_article + articles[id][:title] = "#{articles[id][:title]} (edited)" + visits << [kind, id, articles[id][:title], bodies.sample(random: rng)] + expected_jobs += 1 # broadcasts_to replaces it later + when :create_comment + visits << [kind, id, next_comment_id, "Reader #{next_comment_id}", bodies.sample(random: rng)] + articles[id][:comments] << next_comment_id + next_comment_id += 1 + expected_jobs += 1 # broadcasts_to appends it later + expected_messages += 1 # the article's comment count, replaced now + when :destroy_comment + next if articles[id][:comments].empty? + visits << [kind, id, articles[id][:comments].sample(random: rng)] + articles[id][:comments].delete(visits.last.last) + expected_messages += 2 # broadcasts_to removes it, and the article's comment count + when :destroy_article + next if articles.size < 2 + visits << [kind, id] + expected_messages += 1 + 2 * articles.delete(id)[:comments].size # dependent: :destroy removes each comment + else + visits << [kind, id] + end + visits.last << articles.size << articles.dig(visits.last[1], :comments)&.size + end +ensure + $now = nil +end + +browser = Browser.new(app) +pools = ActiveRecord::Base.connection_handler.connection_pool_list(:writing) + +run_benchmark(10) do + # pin_connection! opens the transaction on Rails 8.1 but not after rails/rails 9e8fe3955b. + pinned = [] + began = [] + pools.each do |pool| + pool.pin_connection!(false) + pinned << pool + connection = pool.lease_connection + next if connection.transaction_open? + connection.begin_transaction(joinable: false, _lazy: false) + began << connection + end + browser.cookie = nil + visits.each_with_index do |(kind, id, *args, count, comments), index| + $now = START_TIME + index + case kind + when :index + body = expect(browser.get("/articles"), 200, "

Articles

") + raise "Expected #{count} articles" unless body.scan('
Comments") + raise "Expected #{comments} comments" unless body.scan('
#{title}") + end + when :update_article + title, body = args + page = expect(browser.get("/articles/#{id}/edit"), 200, "Editing article") + expect(browser.submit(page, "/articles/#{id}", { article: { title: title, body: body } }, method: "patch"), + 303, location: "/articles/#{id}") + expect(browser.get("/articles/#{id}"), 200, "Article was successfully updated.", "#{title}") + when :create_comment + comment_id, commenter, body = args + page = expect(browser.get("/articles/#{id}"), 200, "Add a Comment") + expect(browser.submit(page, "/articles/#{id}/comments", { comment: { commenter: commenter, body: body } }), + 302, location: "/articles/#{id}") + expect(browser.get("/articles/#{id}"), 200, "Comment was successfully created.", "
+ max_size: <%= 256.megabytes %> + namespace: <%= Rails.env %> + +development: + <<: *default + +test: + <<: *default + +production: + database: cache + <<: *default diff --git a/benchmarks/blog/config/database.yml b/benchmarks/blog/config/database.yml new file mode 100644 index 00000000..302d638c --- /dev/null +++ b/benchmarks/blog/config/database.yml @@ -0,0 +1,40 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem "sqlite3" +# +default: &default + adapter: sqlite3 + max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: storage/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: storage/test.sqlite3 + +# Store production database in the storage/ directory, which by default +# is mounted as a persistent Docker volume in config/deploy.yml. +production: + primary: + <<: *default + database: storage/production.sqlite3 + cache: + <<: *default + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate + queue: + <<: *default + database: storage/production_queue.sqlite3 + migrations_paths: db/queue_migrate + cable: + <<: *default + database: storage/production_cable.sqlite3 + migrations_paths: db/cable_migrate diff --git a/benchmarks/blog/config/environment.rb b/benchmarks/blog/config/environment.rb new file mode 100644 index 00000000..cac53157 --- /dev/null +++ b/benchmarks/blog/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/benchmarks/blog/config/environments/production.rb b/benchmarks/blog/config/environments/production.rb new file mode 100644 index 00000000..83b0a3c0 --- /dev/null +++ b/benchmarks/blog/config/environments/production.rb @@ -0,0 +1,93 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). + config.eager_load = true + + # Full error reports are disabled. + config.consider_all_requests_local = false + + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true + + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT with the current request id as a default log tag. + config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) + + # Change to "debug" to log everything (including potentially personally-identifiable information!). + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = "/up" + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Replace the default in-process memory cache store with a durable alternative. + config.cache_store = :solid_cache_store + + # Replace the default in-process and non-durable queuing backend for Active Job. + config.active_job.queue_adapter = :solid_queue + config.solid_queue.connects_to = { database: { writing: :queue } } + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "example.com" } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via bin/rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + + # Let ruby-bench decide whether a JIT runs; Rails enables YJIT by default. + config.yjit = false +end diff --git a/benchmarks/blog/config/importmap.rb b/benchmarks/blog/config/importmap.rb new file mode 100644 index 00000000..909dfc54 --- /dev/null +++ b/benchmarks/blog/config/importmap.rb @@ -0,0 +1,7 @@ +# Pin npm packages by running ./bin/importmap + +pin "application" +pin "@hotwired/turbo-rails", to: "turbo.min.js" +pin "@hotwired/stimulus", to: "stimulus.min.js" +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" +pin_all_from "app/javascript/controllers", under: "controllers" diff --git a/benchmarks/blog/config/initializers/assets.rb b/benchmarks/blog/config/initializers/assets.rb new file mode 100644 index 00000000..48732442 --- /dev/null +++ b/benchmarks/blog/config/initializers/assets.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = "1.0" + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path diff --git a/benchmarks/blog/config/initializers/content_security_policy.rb b/benchmarks/blog/config/initializers/content_security_policy.rb new file mode 100644 index 00000000..d51d7139 --- /dev/null +++ b/benchmarks/blog/config/initializers/content_security_policy.rb @@ -0,0 +1,29 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Automatically add `nonce` to `javascript_tag`, `javascript_include_tag`, and `stylesheet_link_tag` +# # if the corresponding directives are specified in `content_security_policy_nonce_directives`. +# # config.content_security_policy_nonce_auto = true +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true +# end diff --git a/benchmarks/blog/config/initializers/filter_parameter_logging.rb b/benchmarks/blog/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..c0b717f7 --- /dev/null +++ b/benchmarks/blog/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc +] diff --git a/benchmarks/blog/config/initializers/inflections.rb b/benchmarks/blog/config/initializers/inflections.rb new file mode 100644 index 00000000..3860f659 --- /dev/null +++ b/benchmarks/blog/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/benchmarks/blog/config/locales/en.yml b/benchmarks/blog/config/locales/en.yml new file mode 100644 index 00000000..6c349ae5 --- /dev/null +++ b/benchmarks/blog/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/benchmarks/blog/config/queue.yml b/benchmarks/blog/config/queue.yml new file mode 100644 index 00000000..6b143608 --- /dev/null +++ b/benchmarks/blog/config/queue.yml @@ -0,0 +1,18 @@ +default: &default + dispatchers: + - polling_interval: 1 + batch_size: 500 + workers: + - queues: "*" + threads: 3 + processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %> + polling_interval: 1 + +development: + <<: *default + +test: + <<: *default + +production: + <<: *default diff --git a/benchmarks/blog/config/routes.rb b/benchmarks/blog/config/routes.rb new file mode 100644 index 00000000..2d2d3c4a --- /dev/null +++ b/benchmarks/blog/config/routes.rb @@ -0,0 +1,7 @@ +Rails.application.routes.draw do + root "articles#index" + + resources :articles do + resources :comments, only: [:create, :destroy] + end +end diff --git a/benchmarks/blog/config/storage.yml b/benchmarks/blog/config/storage.yml new file mode 100644 index 00000000..927dc537 --- /dev/null +++ b/benchmarks/blog/config/storage.yml @@ -0,0 +1,27 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/benchmarks/blog/db/cable_schema.rb b/benchmarks/blog/db/cable_schema.rb new file mode 100644 index 00000000..9aeefca2 --- /dev/null +++ b/benchmarks/blog/db/cable_schema.rb @@ -0,0 +1,10 @@ +ActiveRecord::Schema[7.1].define(version: 1) do + create_table "solid_cable_messages", force: :cascade do |t| + t.binary "channel", limit: 1024, null: false + t.binary "payload", limit: 536870912, null: false + t.datetime "created_at", null: false + t.integer "channel_hash", limit: 8, null: false + t.index ["channel_hash"], name: "index_solid_cable_messages_on_channel_hash" + t.index ["created_at"], name: "index_solid_cable_messages_on_created_at" + end +end diff --git a/benchmarks/blog/db/cache_schema.rb b/benchmarks/blog/db/cache_schema.rb new file mode 100644 index 00000000..81a410d1 --- /dev/null +++ b/benchmarks/blog/db/cache_schema.rb @@ -0,0 +1,12 @@ +ActiveRecord::Schema[7.2].define(version: 1) do + create_table "solid_cache_entries", force: :cascade do |t| + t.binary "key", limit: 1024, null: false + t.binary "value", limit: 536870912, null: false + t.datetime "created_at", null: false + t.integer "key_hash", limit: 8, null: false + t.integer "byte_size", limit: 4, null: false + t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size" + t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" + t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true + end +end diff --git a/benchmarks/blog/db/queue_schema.rb b/benchmarks/blog/db/queue_schema.rb new file mode 100644 index 00000000..f9a71dab --- /dev/null +++ b/benchmarks/blog/db/queue_schema.rb @@ -0,0 +1,160 @@ +ActiveRecord::Schema[7.1].define(version: 1) do + create_table "solid_queue_blocked_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.string "concurrency_key", null: false + t.datetime "expires_at", null: false + t.datetime "created_at", null: false + t.index [ "concurrency_key", "priority", "job_id" ], name: "index_solid_queue_blocked_executions_for_release" + t.index [ "expires_at", "concurrency_key" ], name: "index_solid_queue_blocked_executions_for_maintenance" + t.index [ "job_id" ], name: "index_solid_queue_blocked_executions_on_job_id", unique: true + end + + create_table "solid_queue_claimed_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.bigint "process_id" + t.datetime "created_at", null: false + t.index [ "job_id" ], name: "index_solid_queue_claimed_executions_on_job_id", unique: true + t.index [ "process_id", "job_id" ], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id" + end + + create_table "solid_queue_failed_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.text "error" + t.datetime "created_at", null: false + t.index [ "job_id" ], name: "index_solid_queue_failed_executions_on_job_id", unique: true + end + + create_table "solid_queue_jobs", force: :cascade do |t| + t.string "queue_name", null: false + t.string "class_name", null: false + t.text "arguments" + t.integer "priority", default: 0, null: false + t.string "active_job_id" + t.datetime "scheduled_at" + t.datetime "finished_at" + t.string "concurrency_key" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "batch_id" + t.index [ "active_job_id" ], name: "index_solid_queue_jobs_on_active_job_id" + t.index [ "batch_id" ], name: "index_solid_queue_jobs_on_batch_id" + t.index [ "class_name" ], name: "index_solid_queue_jobs_on_class_name" + t.index [ "finished_at" ], name: "index_solid_queue_jobs_on_finished_at" + t.index [ "queue_name", "finished_at" ], name: "index_solid_queue_jobs_for_filtering" + t.index [ "scheduled_at", "finished_at" ], name: "index_solid_queue_jobs_for_alerting" + end + + create_table "solid_queue_pauses", force: :cascade do |t| + t.string "queue_name", null: false + t.datetime "created_at", null: false + t.index [ "queue_name" ], name: "index_solid_queue_pauses_on_queue_name", unique: true + end + + create_table "solid_queue_processes", force: :cascade do |t| + t.string "kind", null: false + t.datetime "last_heartbeat_at", null: false + t.bigint "supervisor_id" + t.integer "pid", null: false + t.string "hostname" + t.text "metadata" + t.datetime "created_at", null: false + t.string "name", null: false + t.index [ "last_heartbeat_at" ], name: "index_solid_queue_processes_on_last_heartbeat_at" + t.index [ "name", "supervisor_id" ], name: "index_solid_queue_processes_on_name_and_supervisor_id", unique: true + t.index [ "supervisor_id" ], name: "index_solid_queue_processes_on_supervisor_id" + end + + create_table "solid_queue_ready_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "created_at", null: false + t.index [ "job_id" ], name: "index_solid_queue_ready_executions_on_job_id", unique: true + t.index [ "priority", "job_id" ], name: "index_solid_queue_poll_all" + t.index [ "queue_name", "priority", "job_id" ], name: "index_solid_queue_poll_by_queue" + end + + create_table "solid_queue_recurring_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "task_key", null: false + t.datetime "run_at", null: false + t.datetime "created_at", null: false + t.index [ "job_id" ], name: "index_solid_queue_recurring_executions_on_job_id", unique: true + t.index [ "task_key", "run_at" ], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true + end + + create_table "solid_queue_recurring_tasks", force: :cascade do |t| + t.string "key", null: false + t.string "schedule", null: false + t.string "command", limit: 2048 + t.string "class_name" + t.text "arguments" + t.string "queue_name" + t.integer "priority", default: 0 + t.boolean "static", default: true, null: false + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index [ "key" ], name: "index_solid_queue_recurring_tasks_on_key", unique: true + t.index [ "static" ], name: "index_solid_queue_recurring_tasks_on_static" + end + + create_table "solid_queue_scheduled_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "scheduled_at", null: false + t.datetime "created_at", null: false + t.index [ "job_id" ], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true + t.index [ "scheduled_at", "priority", "job_id" ], name: "index_solid_queue_dispatch_all" + end + + create_table "solid_queue_semaphores", force: :cascade do |t| + t.string "key", null: false + t.integer "value", default: 1, null: false + t.datetime "expires_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index [ "expires_at" ], name: "index_solid_queue_semaphores_on_expires_at" + t.index [ "key", "value" ], name: "index_solid_queue_semaphores_on_key_and_value" + t.index [ "key" ], name: "index_solid_queue_semaphores_on_key", unique: true + end + + create_table "solid_queue_batches", force: :cascade do |t| + t.string "active_job_batch_id" + t.string "description" + t.text "on_finish" + t.text "on_success" + t.text "on_failure" + t.text "metadata" + t.integer "total_jobs", default: 0, null: false + t.integer "completed_jobs", default: 0, null: false + t.integer "failed_jobs", default: 0, null: false + t.datetime "enqueued_at" + t.datetime "finished_at" + t.datetime "failed_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index [ "active_job_batch_id" ], name: "index_solid_queue_batches_on_active_job_batch_id", unique: true + t.index [ "finished_at" ], name: "index_solid_queue_batches_on_finished_at" + end + + create_table "solid_queue_batch_executions", force: :cascade do |t| + t.bigint "job_id", null: false + t.bigint "batch_id", null: false + t.datetime "created_at", null: false + t.index [ "job_id" ], name: "index_solid_queue_batch_executions_on_job_id", unique: true + t.index [ "batch_id" ], name: "index_solid_queue_batch_executions_on_batch_id" + end + + add_foreign_key "solid_queue_batch_executions", "solid_queue_batches", column: "batch_id", on_delete: :cascade + add_foreign_key "solid_queue_batch_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade +end diff --git a/benchmarks/blog/db/schema.rb b/benchmarks/blog/db/schema.rb new file mode 100644 index 00000000..54ddaa86 --- /dev/null +++ b/benchmarks/blog/db/schema.rb @@ -0,0 +1,31 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.1].define(version: 2026_11_06_133242) do + create_table "articles", force: :cascade do |t| + t.string "title" + t.text "body" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "comments", force: :cascade do |t| + t.integer "article_id", null: false + t.string "commenter" + t.text "body" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["article_id"], name: "index_comments_on_article_id" + end + + add_foreign_key "comments", "articles" +end diff --git a/benchmarks/blog/db/seeds.rb b/benchmarks/blog/db/seeds.rb new file mode 100644 index 00000000..ea295830 --- /dev/null +++ b/benchmarks/blog/db/seeds.rb @@ -0,0 +1,35 @@ +# Sample articles and comments for the blog demo +# Seeds are idempotent - only run if database is empty +return if Article.count > 0 + +article1 = Article.create!( + title: "Getting Started with Rails", + body: "Rails is a web application framework running on the Ruby programming language. It makes building web apps faster and easier with conventions over configuration." +) + +article1.comments.create!( + commenter: "Alice", + body: "Great introduction! Rails really does make development faster." +) + +article1.comments.create!( + commenter: "Bob", + body: "I love how Rails handles database migrations automatically." +) + +article2 = Article.create!( + title: "Understanding MVC Architecture", + body: "MVC stands for Model-View-Controller. Models handle data and business logic, Views display information to users, and Controllers coordinate between them." +) + +article2.comments.create!( + commenter: "Carol", + body: "This pattern really helps keep code organized!" +) + +article3 = Article.create!( + title: "Ruby2JS: Rails Everywhere", + body: "Ruby2JS transpiles Ruby to JavaScript, enabling Rails applications to run in browsers, on Node.js, and at the edge. Same code, different runtimes." +) + +puts "Created #{Article.count} articles and #{Comment.count} comments" diff --git a/benchmarks/blog/storage/.keep b/benchmarks/blog/storage/.keep new file mode 100644 index 00000000..e69de29b