Repository navigation
perf: inline single-consumer modules, lazy-load heavy deps, and pause off-screen animations - #169
Conversation
… off-screen animations
There was a problem hiding this comment.
📋 Review Summary
This PR introduces AGENTS.md to document native ESM architecture and performance conventions, and applies a set of network and runtime optimisations across the component library. Single-consumer style, animation, controller, and validator modules are co-located into their owning component files, heavy optional dependencies (md-search in md-app-bar and md-datetime-picker-dialog / md-icon-button in md-text-field) are lazy-loaded via dynamic import(), unused lit/decorators.js and lit/directives/when.js imports as well as broken //# sourceMappingURL= comments are removed, and continuous requestAnimationFrame loops in md-loading and wavy md-progress now pause when off-screen while avoiding per-frame matchMedia and array allocations. A new tests/performance_test.js suite verifies these guards.
🔍 General Feedback
- Co-locating single-consumer
*-styles.js,animations.js,surfacePositionController.js, and validator files into their owning components eliminates sequential ESM waterfall requests while preserving existing public exports (iconButtonStyles,Corner,SurfacePositionController,RadioValidator,SelectValidator,TextFieldValidator, etc.). - The runtime optimisations in
indicators/loading.jsandindicators/progress.js(module-levelMediaQueryListcaching, singlegetComputedStylelookup per colour resolution, reusedFloat32Arraylerp buffer, and off-screen pausing viacontentvisibilityautostatechangewith anIntersectionObserverfallback) directly reduce frame-time work. - Replacing the imperative
addEventListener('confirm', ...)call insideopenPickerDialog()with declarative@confirm=${this.handlePickerConfirm}intext/text-field.jsalso prevents duplicate listener accumulation across repeated picker openings.
📊 Token Usage & Cost Efficiency
| Metric | Value |
|---|---|
| Input Tokens (uncached) | 3,688 |
| Input Tokens (cached) | 688,105 (⚡ 99.5% cached) |
| Thinking / Reasoning Tokens | 14,240 |
| Output Tokens | 1,367 |
| Total Session Tokens | 707,400 |
| Cost (uncached input) | $0.0055 |
| Cost (cached input) | $0.0516 |
| Cost (thinking / reasoning) | $0.1068 |
| Cost (response output) | $0.0103 |
| Estimated Total Cost | $0.1742 |
Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.
…d, and lit import
There was a problem hiding this comment.
📋 Review Summary
This PR optimises network waterfall and runtime performance for unbundled native ESM delivery, introducing AGENTS.md to codify the architecture guidelines and tests/performance_test.js to guard against regressions. Single-consumer style, animation, positioning, and validator modules have been co-located into their owning components, heavy optional dependencies (search in md-app-bar and pickers in md-text-field) are now dynamically imported on demand, unused lit/decorators.js and lit/directives/when.js imports as well as broken sourceMappingURL comments have been removed, and continuous rAF animations in md-loading and wavy md-progress now pause when off-screen with reduced per-frame allocations. All six previously raised review comments have been addressed. Only minor defensive improvements remain around handling rejected dynamic imports in openPickerDialog() and feature-detecting the contentvisibilityautostatechange event directly.
✅ Resolved Items from Prior Reviews
- Reset _searchDepPromise to null on import failure in app/bar.js so transient failures can be retried. (
app/bar.js:19) - Attached a .catch(() => {}) handler to the preload call to ensureSearchDep() in willUpdate() in app/bar.js. (
app/bar.js:110) - Reset _pickerDepsPromise to null on import failure in text/text-field.js so transient failures can be retried. (
text/text-field.js:179) - Attached a .catch(() => {}) handler to the preload call to ensurePickerDeps() in updated() in text/text-field.js. (
text/text-field.js:603) - Added an isConnected check after awaiting ensurePickerDeps() in openPickerDialog() in text/text-field.js. (
text/text-field.js:738) - Consolidated the duplicate 'lit' import in select/select.js into a single import statement. (
select/select.js:1)
🔍 General Feedback
- Co-locating single-consumer CSS, controllers, animations, and validators directly into their component files eliminates unnecessary HTTP round trips in an unbundled ESM setup while keeping public exports (such as iconButtonStyles, DIALOG_DEFAULT_OPEN_ANIMATION, Corner, SurfacePositionController, and the validator classes) intact.
- Replacing per-frame array allocations in indicators/loading.js with a reused Float32Array buffer and caching MediaQueryList and getComputedStyle lookups significantly reduces GC pressure and style recalculation overhead during animation frames.
- Adding tests/performance_test.js provides automated regression coverage for lazy-loaded optional dependencies, forbidden Lit subpath imports, broken sourceMappingURL comments, and off-screen rAF pausing.
📊 Token Usage & Cost Efficiency
| Metric | Value |
|---|---|
| Input Tokens (uncached) | 2,909 |
| Input Tokens (cached) | 689,225 (⚡ 99.5% cached) |
| PR Comments History Tokens | 802 |
| Thinking / Reasoning Tokens | 11,273 |
| Output Tokens | 1,208 |
| Total Session Tokens | 705,417 |
| Cost (uncached input) | $0.0056 |
| Cost (cached input) | $0.0517 |
| Cost (thinking / reasoning) | $0.0845 |
| Cost (response output) | $0.0091 |
| Estimated Total Cost | $0.1509 |
Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.
There was a problem hiding this comment.
📋 Review Summary
This pull request optimises unbundled native ESM network loading and runtime animation performance across the library, and documents these standards in AGENTS.md. Single-consumer style, animation, validator, ARIA, and surface-positioning modules are co-located into their owning components (buttons/icon-button.js, dialog/dialog.js, indicators/progress.js, internal/aria/delegate.js, menu/menu.js, radio/radio.js, select/select.js, sheet/sheet.js, and text/text-field.js), while optional heavy dependencies (md-search in app/bar.js and the datetime picker dialog plus md-icon-button in text/text-field.js) are dynamically imported on demand. It also removes unused lit/decorators.js and lit/directives/when.js imports as well as stale sourceMappingURL comments, eliminates per-frame array allocations and matchMedia lookups in indicators/loading.js and indicators/progress.js, pauses off-screen rAF loops via contentvisibilityautostatechange with an IntersectionObserver fallback, and adds tests/performance_test.js to guard these invariants. All previously raised review threads have been addressed cleanly.
✅ Resolved Items from Prior Reviews
- Reset _searchDepPromise to null on failure in ensureSearchDep() so transient import errors can be retried. (
app/bar.js:19) - Added a .catch() handler to ensureSearchDep() in willUpdate() to avoid unhandled promise rejections. (
app/bar.js:110) - Reset _pickerDepsPromise to null on failure in ensurePickerDeps() so transient picker module load errors can be retried. (
text/text-field.js:179) - Added a .catch() handler to the ensurePickerDeps() preload call in updated(). (
text/text-field.js:603) - Added an isConnected guard after awaiting ensurePickerDeps() in openPickerDialog() so disconnected text fields do not open an orphaned dialog. (
text/text-field.js:735) - Consolidated css and render into the main lit import in select/select.js. (
select/select.js:1) - Wrapped await ensurePickerDeps() in a try/catch block inside openPickerDialog() so failed loads degrade gracefully without unhandled rejections. (
text/text-field.js:738) - Updated off-screen visibility feature detection in indicators/loading.js to check 'oncontentvisibilityautostatechange' in this rather than CSS contentVisibility support. (
indicators/loading.js:495) - Updated off-screen visibility feature detection in indicators/progress.js to check 'oncontentvisibilityautostatechange' in this rather than CSS contentVisibility support. (
indicators/progress.js:824)
🔍 General Feedback
- Inlining single-consumer stylesheets, validators, and animation definitions directly into their owning component modules meaningfully reduces sequential ESM HTTP requests and waterfall latency for unbundled browser consumers while preserving existing public exports (such as iconButtonStyles, DIALOG_DEFAULT_OPEN_ANIMATION, Corner, SurfacePositionController, RadioValidator, SelectValidator, TextFieldValidator, ARIA_PROPERTIES, circularStyles, and linearStyles).
- Lazy-loading search/search.js in app/bar.js and pickers/datetime-picker-dialog.js plus buttons/icon-button.js in text/text-field.js avoids loading unused component trees for standard app bars and text inputs, and switching text/text-field.js to a declarative @confirm binding also prevents accumulating duplicate confirm event listeners across repeated dialog opens.
- Reusing a pre-allocated Float32Array morph buffer, hoisting matchMedia queries out of the animation loop, and pausing rAF loops when off-screen in indicators/loading.js and indicators/progress.js are solid runtime optimisations, backed by unit tests in tests/performance_test.js.
📊 Token Usage & Cost Efficiency
| Metric | Value |
|---|---|
| Input Tokens (uncached) | 2,362 |
| Input Tokens (cached) | 689,847 (⚡ 99.5% cached) |
| PR Comments History Tokens | 1,350 |
| Thinking / Reasoning Tokens | 12,789 |
| Output Tokens | 1,165 |
| Total Session Tokens | 707,513 |
| Cost (uncached input) | $0.0056 |
| Cost (cached input) | $0.0517 |
| Cost (thinking / reasoning) | $0.0959 |
| Cost (response output) | $0.0087 |
| Estimated Total Cost | $0.1620 |
Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://remove-material-line-limit-material.treeder.workers.dev (commit fe2473f)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
There was a problem hiding this comment.
📋 Review Summary
This pull request eliminates unnecessary HTTP/ESM waterfall hops and improves runtime performance for unbundled browser loading, while documenting the architecture rules in AGENTS.md. Single-consumer style, animation, ARIA, position-controller, and validator sub-modules have been co-located into their owning component files, heavy optional dependencies in md-text-field and md-app-bar are now dynamically imported, unused lit/decorators.js and lit/directives/when.js imports as well as broken sourceMappingURL comments have been removed, and off-screen animation pausing plus zero-allocation rAF rendering have been added to md-loading and wavy md-progress. All previously raised review comments have been addressed and verified alongside new Node test guards in tests/performance_test.js.
✅ Resolved Items from Prior Reviews
- Reset _searchDepPromise to null in a .catch() handler so transient network failures when lazy-loading search/search.js can be retried. (
app/bar.js:19) - Attached a .catch() handler to ensureSearchDep() in willUpdate() to avoid unhandled promise rejections when offline. (
app/bar.js:110) - Reset _pickerDepsPromise to null on failure in ensurePickerDeps() so subsequent clicks can retry loading the picker modules. (
text/text-field.js:179) - Attached a .catch() handler to ensurePickerDeps() when preloading picker dependencies in updated(). (
text/text-field.js:603) - Added an isConnected check after awaiting ensurePickerDeps() in openPickerDialog() to avoid opening an orphaned dialog. (
text/text-field.js:735) - Consolidated css and render into the single 'lit' import declaration in select/select.js. (
select/select.js:1) - Wrapped await ensurePickerDeps() in a try/catch block in openPickerDialog() so failed loads degrade gracefully without an unhandled rejection. (
text/text-field.js:738) - Switched off-screen pause detection in md-loading to feature-detect 'oncontentvisibilityautostatechange' in this before falling back to IntersectionObserver. (
indicators/loading.js:495) - Switched off-screen pause detection in md-progress to feature-detect 'oncontentvisibilityautostatechange' in this before falling back to IntersectionObserver. (
indicators/progress.js:824) - Moved SelectValidator below the static module imports and removed the leading blank line in select/select.js. (
select/select.js:56)
🔍 General Feedback
- Co-locating single-consumer sub-modules (icon-button-styles.js, dialog/internal/animations.js, progress-styles.js, sheet-styles.js, surfacePositionController.js, aria.js, and single-component validators) directly reduces sequential ESM requests without breaking existing public exports such as iconButtonStyles, DIALOG_DEFAULT_OPEN_ANIMATION, Corner, or the validator classes.
- Shared CheckboxValidator remains extracted in labs/behaviors/validators/checkbox-validator.js for reuse between md-checkbox and md-switch, aligning cleanly with AGENTS.md.
- Moving the confirm listener onto the template via @confirm=${this.handlePickerConfirm} in text/text-field.js also prevents duplicate listener registration when the picker is opened multiple times.
- Caching MediaQueryList instances, reusing computed styles across _resolveColor calls, and using a pre-allocated Float32Array buffer in indicators/loading.js remove per-frame allocations and repeated style/media-query lookups inside rAF loops.
- tests/performance_test.js adds automated regression checks for lazy imports, disallowed Lit subpath imports, broken sourceMappingURL comments, and contentvisibilityautostatechange pause/resume behaviour.
📊 Token Usage & Cost Efficiency
| Metric | Value |
|---|---|
| Input Tokens (uncached) | 1,781 |
| Input Tokens (cached) | 690,435 (⚡ 99.5% cached) |
| PR Comments History Tokens | 1,922 |
| Thinking / Reasoning Tokens | 10,421 |
| Output Tokens | 1,062 |
| Total Session Tokens | 705,621 |
| Cost (uncached input) | $0.0056 |
| Cost (cached input) | $0.0518 |
| Cost (thinking / reasoning) | $0.0782 |
| Cost (response output) | $0.0080 |
| Estimated Total Cost | $0.1435 |
Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.
There was a problem hiding this comment.
📋 Review Summary
This pull request optimises the library for unbundled native ESM browser delivery by co-locating single-consumer stylesheets, animations, controllers, and validators directly into their owning component modules, adding lazy dynamic imports for heavy optional dependencies in md-app-bar and md-text-field, removing unused lit/decorators.js and when.js imports alongside broken sourceMappingURL comments, and pausing off-screen requestAnimationFrame loops in md-loading and md-progress. It also introduces AGENTS.md to document these architectural and performance standards, bumps the package version to 3.7.0 with an npm test script, and adds regression tests in tests/performance_test.js. All ten review threads raised in previous iterations have been cleanly addressed, and the changes are ready for approval.
✅ Resolved Items from Prior Reviews
- Reset _searchDepPromise to null on failure in ensureSearchDep() so transient import errors can be retried. (
app/bar.js:19) - Attached a .catch(() => {}) handler when preloading search dependencies in willUpdate() to avoid unhandled promise rejections. (
app/bar.js:110) - Reset _pickerDepsPromise to null on failure in ensurePickerDeps() so transient picker module load errors can be retried. (
text/text-field.js:179) - Attached a .catch(() => {}) handler when preloading picker dependencies in updated() to avoid unhandled promise rejections. (
text/text-field.js:603) - Added an isConnected check after awaiting ensurePickerDeps() in openPickerDialog() so detached fields do not open an orphaned dialog. (
text/text-field.js:735) - Consolidated css and render into the single lit import declaration. (
select/select.js:1) - Wrapped await ensurePickerDeps() in a try/catch block in openPickerDialog() so click-triggered failures degrade gracefully. (
text/text-field.js:738) - Updated feature detection for contentvisibilityautostatechange in connectedCallback() to check 'oncontentvisibilityautostatechange' in this directly. (
indicators/loading.js:495) - Updated feature detection for contentvisibilityautostatechange in _setupVisibilityObserver() to check 'oncontentvisibilityautostatechange' in this directly. (
indicators/progress.js:824) - Moved SelectValidator below all static imports and removed the leading blank line. (
select/select.js:56)
🔍 General Feedback
- Co-locating single-consumer modules (styles, animations, SurfacePositionController, aria constants, and validators) while preserving public exports such as iconButtonStyles, DIALOG_DEFAULT_OPEN_ANIMATION, circularStyles, linearStyles, Corner, RadioValidator, SelectValidator, and TextFieldValidator eliminates sequential ESM waterfall requests without breaking external consumers.
- Converting md-app-bar (type='search') and md-text-field (date/time/datetime-local) to lazy dynamic imports avoids eagerly loading md-search, md-icon-button, and md-datetime-picker-dialog for standard component usage, and switching md-text-field to a declarative @confirm handler also fixes a pre-existing duplicate listener leak.
- Runtime optimisations in md-loading and md-progress are well implemented: caching MediaQueryList references, reusing a single Float32Array morph buffer in md-loading, resolving getComputedStyle once per colour update, and pausing off-screen rAF loops via contentvisibilityautostatechange with an IntersectionObserver fallback.
- AGENTS.md clearly explains the rationale behind co-location and unbundled ESM performance constraints, and tests/performance_test.js provides automated static and runtime guards via the new npm test script.
📊 Token Usage & Cost Efficiency
| Metric | Value |
|---|---|
| Input Tokens (uncached) | 1,516 |
| Input Tokens (cached) | 691,093 (⚡ 99.5% cached) |
| PR Comments History Tokens | 2,212 |
| Thinking / Reasoning Tokens | 9,599 |
| Output Tokens | 897 |
| Total Session Tokens | 705,317 |
| Cost (uncached input) | $0.0056 |
| Cost (cached input) | $0.0518 |
| Cost (thinking / reasoning) | $0.0720 |
| Cost (response output) | $0.0067 |
| Estimated Total Cost | $0.1361 |
Gemini 4 Hydrogen: standard tier, global endpoint; regional endpoints are 10% higher.
Cache reads are priced here, but context-cache STORAGE, where the model charges for it separately per token-hour, is not included, so the figure can run slightly low.
Summary
Because
material-esm/materialships unbundled native ES modules directly to browsers (e.g. via jsDelivr +<script type="importmap">), splitting components into single-consumer*-styles.jsor helper files to stay under a 1,000-line limit adds extra HTTP requests and sequential ESM waterfall hops. This PR documents the no-1,000-line-limit policy inAGENTS.md, consolidates single-consumer modules, and introduces targeted network and runtime performance improvements.Key Changes
AGENTS.md): Documented the exemption from the 1,000-line file limit and established ESM network/runtime performance standards for this repository.buttons/icon-button-styles.js→buttons/icon-button.js(preservingiconButtonStylesexport)indicators/progress-styles.js→indicators/progress.jssheet/sheet-styles.js→sheet/sheet.jsinternal/aria/aria.js→internal/aria/delegate.js(removes 1 waterfall hop + 1 request across 14 components)dialog/internal/animations.js→dialog/dialog.jsmenu/controllers/surfacePositionController.js→menu/menu.js(preservingCornerexport)radio-validator.js,select-validator.js, andtext-field-validator.jsintoradio/radio.js,select/select.js, andtext/text-field.jstext/text-field.js: Dynamically importspickers/datetime-picker-dialog.jsandbuttons/icon-button.jsonly whentypeisdate,time, ordatetime-local(cuts static local deps from 29 @ depth 5 → 11 @ depth 2). Also switched pickerconfirmhandling to declarative@confirmto prevent stacking listeners.app/bar.js: Dynamically importssearch/search.jsonly whentype="search"and removed unusedicon/icon.js(cuts static local deps from 16 @ depth 4 → 2 @ depth 1).lit/decorators.jsimports fromcheckbox/checkbox.js,menu/menu.js,nav/tab.js,switch/switch.js, andlabs/behaviors/focusable.js.lit/directives/when.jsimport inslider/slider.jswith ternaries.nav/tab.js,pickers/date-picker.js,internal/field/field.js,select/select.js,nav/rail.js, andpickers/datetime-picker-dialog.js.//# sourceMappingURL=...comments pointing to nonexistent.js.mapfiles.indicators/loading.js&indicators/progress.js):requestAnimationFrameloops when off-screen viacontentvisibilityautostatechange(withIntersectionObserverfallback).prefers-reduced-motion(andforced-colors)MediaQueryListat module level instead of callingwindow.matchMedia()60 times/sec.md-loadingusing a reusableFloat32Arraybuffer, and consolidatedgetComputedStyle(this)to a single call per color check.Verification
tests/performance_test.jscovering import regression guards and off-screen animation pausing.node --test tests/*_test.js: 15/15 passing.