perf: defer HTML formatter imports for browser graders - #381
Conversation
Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request optimizes the startup performance of browser graders by deferring the loading of HTML formatting and encoding detection dependencies. By moving these imports to the point of execution within the HTML normalization process, the application avoids unnecessary overhead for simple tasks that do not require these modules, resulting in faster execution times and reduced resource usage. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Imports were heavy, slow to start, Now deferred, they play their part. Only when the HTML calls, The formatter wakes within the halls. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors packages/problem-utils-browser/src/html.ts by replacing static imports of html-encoding-sniffer, prettier, and prettier-plugin-organize-attributes with dynamic imports inside the loadFormattedHtmlForScreenshot function. This defers the loading of these dependencies until they are actually needed. There are no review comments, and I have no feedback to provide.
Close #377
Requirements
Why
Importing the browser package root loaded Prettier, its HTML parser/plugin and encoding detection even for simple DOM checks. Defer these dependencies until HTML screenshot normalization needs them. This removes unused startup work without adding a public subpath or migrating callers.
Customer Summary
Simple browser graders start with fewer loaded modules. HTML normalization and PDF generation retain their existing behavior and API.
Technical Summary
In loadFormattedHtmlForScreenshot, load html-encoding-sniffer, prettier and prettier-plugin-organize-attributes together after fetching a successful HTML response. Module caching shares those imports across concurrent and later calls. Retain encoding detection, format options and the unformatted fallback; dependency import failures also enter that fallback. PDF Markdown dependencies remain isolated behind the existing /pdf export.
Testing
bun run verify-full passed: 192 unit tests and 116 E2E tests, including HTML comparison/encoding/interception, DOM JavaScript, Tomcat navigation and CommonJS PDF generation. Existing unrelated template-expression lint warnings remain.
Actual browserLifecycle and javascriptDom grader fixtures emitted ACCEPTED and showed zero loaded prettier/marked/html-encoding-sniffer modules in Bun module cache after grading.
Local macOS fresh-process benchmark: Bun 1.4.2, Puppeteer 25.10.0, two warmups per variant and 15 samples each, alternating order. Median dynamic import: 93.559ms before, 76.264ms after; median process wall time: 103.311ms before, 85.655ms after. Same dependency versions on both sides. Before import loaded seven matching formatter/encoding modules; after loaded zero. These are local measurements, not Cloud Run latency estimates.
Real CommonJS HTML screenshot and attribute-normalization checks passed on Node 26.8.1 and Bun 1.4.2.
Notes
Review run 2f18d29c finished with six of seven reviewers successful and no findings. Claude weekly quota prevented the remaining review (reset reported as 2026-09-15 21:00 UTC), so coverage remains incomplete. CI and the merge-readiness check passed.