Repository navigation
Conversation
Route and ScreenshotUtils required 'mime/types' at load time, so every `require 'playwright'` paid for the whole MIME database even though it is only consulted by `Route#fulfill(path:)` and by screenshots given a `path:` without a `type:`. Requiring it inside those two methods, as playwright.rb already does for the WebSocket transport, cuts `require 'playwright'` from about 215k to 80k allocated objects and about 3.8 MB of RSS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@czj is attempting to deploy a commit to the Yusuke Iwaki's projects Team on Vercel. A member of the Team first needs to authorize it. |
czj
marked this pull request as ready for review
October 24, 2026 19:13
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Yusuke, and thank you for keeping this client so close to upstream Playwright!
RouteandScreenshotUtilsrequiremime/typesat the top of their files, and sincechannel_owner.rbloads every channel owner, eachrequire 'playwright'loads the whole MIME database. Yet it is only consulted in two places:Route#fulfill(path:), to guess the content type, andscreenshot(path:)without an explicittype:. Most test suites never reach either, but they pay the load cost on every boot, and Rails apps that eager-load their test dependencies pay it in every process.This PR moves the
requireinto those two methods, asplaywright.rbalready does forplaywright/web_socket_client.requireis thread-safe and becomes a cheap lookup after the first call. I added a unit spec forScreenshotUtils.determine_type(which had none) and one that checks, in a subprocess, thatrequire 'playwright'no longer loadsmime/types. That spec fails onmain.Measured with
ruby -I lib -e "require 'playwright'"(no Bundler), Ruby 4.0.8 arm64, mime-types 3.7.0, median of 5 runs:require 'playwright'mainObjectSpace.memsize_of_allThe unit suite passes (36 examples, 2 pending as before), and so do
request_fulfill_spec,route_specandscreenshot_specagainst playwright-core 1.64.0 on Chromium (41 examples). I also checked by hand thatroute.fulfill(path: 'empty.html')still answers withtext/html.One thing to be aware of: code that used
MIME::Typeswithout requiring it, relying on Playwright to load it, would now need its ownrequire 'mime/types'.🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)