Skip to content

perf: defer HTML formatter imports for browser graders - #381

Merged
exKAZUu merged 1 commit into
mainfrom
perf/lazy-browser-formatters
Sep 13, 2026
Merged

exKAZUu merged 1 commit into
mainfrom
perf/lazy-browser-formatters

Conversation

@exKAZUu

@exKAZUu exKAZUu commented Sep 13, 2026

Copy link
Copy Markdown
Member

Close #377

Requirements

  • required: Complete the remaining shared-package import optimization requested in issue feat: reduce browser utility imports for simple graders #377.
  • required: Simple browser and DOM JavaScript graders must not load unused HTML formatter or Markdown modules.
  • required: Preserve public browser exports, native Puppeteer pages, dialog ownership, grading feedback and HTML/PDF behavior.
  • required: Demonstrate the loaded module graph and repeat pinned-engine fresh-process measurements without Cloud Run extrapolation.
  • chosen: Load encoding detection and HTML formatting dependencies inside the existing asynchronous formatting operation, keeping all consumer imports unchanged.

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.

Co-authored-by: WillBooster (Codex CLI) <agent@willbooster.com>
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • Deferred Dependency Loading: Moved heavy dependencies like Prettier and html-encoding-sniffer from top-level imports to dynamic imports within the HTML formatting function.
  • Performance Optimization: Reduced startup time and memory footprint for simple browser graders by ensuring unused formatter modules are not loaded during initialization.
  • Verification: Validated the changes with full unit and E2E test suites, confirming significant improvements in process wall time and module loading efficiency.
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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@exKAZUu exKAZUu self-assigned this Sep 13, 2026
@exKAZUu
exKAZUu merged commit 598869e into main Sep 13, 2026
6 checks passed
@exKAZUu
exKAZUu deleted the perf/lazy-browser-formatters branch September 13, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: reduce browser utility imports for simple graders

1 participant