Skip to content

Fix Quadratic Polling#111

Merged
EdgeTypE merged 11 commits into
EdgeTypE:mainfrom
WhiteLicorice:fix/quadratic-polling
Jul 17, 2026
Merged

Fix Quadratic Polling#111
EdgeTypE merged 11 commits into
EdgeTypE:mainfrom
WhiteLicorice:fix/quadratic-polling

Conversation

@WhiteLicorice

Copy link
Copy Markdown
Contributor

PR fixes the root causes of the performance degradation in #105 and repeated storage activity in #108 across the Chrome-target build and Firefox.

Message scanning and pricing performance (#105)

  • Replace repeated full-history filtering, reverse scans, and indexOf lookups with an ordered message registry backed by weak-map indexes.
  • Keep the latest assistant message cached during ordinary append processing.
  • Reserve linear registry reconstruction for initial scans and uncommon structural changes.
  • Replace repeated full-message token-total enumeration with per-message pricing contributions and delta updates.
  • Correctly remove pricing contributions when messages are disposed or sessions reset.
  • Preserve connected messages during DOM reparenting and keep their registry position synchronized.
  • Reconcile an existing message host wrapper after reparenting without duplicating or recreating its rendered content.

Remote persistence and storage stability (#108)

  • Add an explicit startup barrier covering remote status, remote configuration, and locale persistence.
  • Make remote-config mutations await their corresponding storage operation so tests and callers observe the actual persistence boundary.
  • Correct Firefox remote persistence by invoking fetch through a bound adapter.
  • Make storage-listener registration return one stable cleanup handle.
  • Prevent stale cleanup handles from removing a newer listener after rebinding.
  • Isolate listener failures so one callback cannot prevent later queued deliveries.
  • Reject malformed remote configuration and locale roots, including arrays and primitive messages values.
  • Preserve deep-equality suppression so reordered but otherwise identical configuration produces no additional write or update event.

Browser test infrastructure

  • Add a dedicated real-Firefox extension fixture using Selenium, GeckoDriver, and BiDi interception.
  • Run the same Title: UI lag after multiple conversations #105 performance, High CPU/memory on idle chat.deepseek.com tab (storage.onChanged firing excessively) #108 storage-quiescence, and host-wrapper contracts in Firefox and Chrome-target Chromium.
  • Replace fixed post-write delays with observable startup and storage-quiescence waits.
  • Require exactly one event/write for a changed configuration and zero additional activity for a reordered identical replacement.
  • Intercept all Firefox HTTP(S) traffic and reject unexpected external requests.
  • Make unmatched requests fail the Chromium fixture instead of merely logging them.
  • Add deterministic Google Fonts handling and reject nonexistent locale fixtures.
  • Capture Firefox screenshots and page HTML when a test fails.
  • Strengthen host-wrapper assertions to verify ownership, adjacency, layout, and the expected message.

Playwright runs the exact production dist-chrome build in bundled Chromium. Current branded Chrome releases cannot side-load unpacked extensions through Playwright, so store-installed branded-Chrome verification remains a manual release check: https://playwright.dev/docs/chrome-extensions

Testing

  • npm test
    • production Chrome and Firefox builds passed
    • 73 unit-test files passed
    • 1,098 unit tests passed
    • coverage thresholds passed
    • 34 Chromium E2E tests passed
    • 4 real-Firefox E2E tests passed
  • npm run test:android
    • Android production build passed
    • 21 Android E2E tests passed
  • Focused regression suite
    • 230 tests passed
  • git diff --check

Closes #105
Closes #108

- Implemented session-specific message retention in history handling.
- Added functionality to dispose of detached message nodes and overlays.
- Improved incremental scanning of message nodes for better performance.
- Updated remote config synchronization to prevent unnecessary storage writes.
- Enhanced tests for remote config and storage change events.
- Implement centralized message host ownership in host.js
- Refactor history message handling to enforce current session constraints
- Improve load history functionality with session-specific caching
- Update message processing to clean up associated hosts and improve context handling
- Enhance scanner functionality for better message processing and state management
- Normalize remote config handling for improved storage hygiene
- Add comprehensive tests for scanner scheduling and message processing
- Implement async flow tests for load-all-history, covering scenarios such as request dispatching, loading states, and response handling.
- Enhance scanner tests to ensure proper behavior with #bds-root isolation, including message processing and timer management.
- Introduce new tests for storage mock contracts to validate storage interactions and event emissions.
- Create a new test suite for host wrapper functionality, ensuring correct wrapper creation, host management, and message reparenting behavior.
- Update CI configuration to use the correct Firefox binary path.
- Implement deep equality check for remote config comparison to avoid unnecessary writes.
- Refactor message scanning logic to ensure only valid nodes trigger scans.
- Improve wrapper management for message nodes during reparenting.
- Add fixtures for remote config and status in tests.
- Enhance tests for storage stability and message handling across sessions.
…dicated functions and implementing deep equality checks for config updates
- Updated `setupBridgeEvents` to return a cleanup function that removes all registered listeners, allowing for fresh setups.
- Consolidated event handler registration into a single object for better management and cleanup.
- Enhanced error handling and logging for network state and session data events.

Enhance remote config persistence with structured error handling

- Replaced structural equality checks with a deep equality function for more accurate change detection in `RemoteConfigManager`.
- Improved error handling in `persistRemoteConfig`, `persistRemoteStatus`, and `persistLocales` to return detailed error messages.
- Consolidated storage updates to minimize writes and ensure atomic updates for config and metadata.

Refactor host wrapper management for better DOM handling

- Improved `getOrCreateWrapper` to handle detached messages more effectively, ensuring wrappers are removed from the DOM when messages are detached.
- Added tests to verify the behavior of wrapper detachment and reconnection.

Update integration tests for persistence and host management

- Enhanced tests for `persistRemoteConfig`, `persistRemoteStatus`, and `persistLocales` to cover new error handling and atomic updates.
- Added tests for host wrapper behavior during detachment and reconnection scenarios.
…le validation

- Added checks to ensure download cards are correctly nested within wrappers in e2e tests.
- Refactored fixture request handling in e2e tests to use a shared resolver for improved maintainability.
- Introduced lifecycle tests for setupBridgeEvents to validate cleanup and listener behavior.
- Enhanced scanner tests to ensure only new messages are processed during transitions.
- Expanded storage mock contracts to cover various scenarios including reset behavior and listener independence.
- Implemented deepEqual tests to validate object and array equality, including nested structures and key reordering.
- Introduced functions to manage known nodes more effectively, including rebuilding known nodes, updating indexes, and removing nodes.
- Improved the registration process for known nodes to ensure accurate tracking of the latest assistant message.
- Refactored the scanPage function to utilize the new known node management system, enhancing performance and reliability.

feat(storage): improve storage change listener management

- Refactored the storage change listener to ensure idempotency and proper cleanup.
- Added a mechanism to handle listener registration and cleanup more effectively, preventing stale references.

feat(remote-config): update remote config methods for async handling

- Modified applyRemote, replaceRemote, and resetToBuiltin methods to return promises, ensuring proper handling of asynchronous storage operations.
- Enhanced error handling during persistence operations to provide better feedback on failures.

test(e2e): enhance Firefox extension tests with improved stability checks

- Added functionality to wait for storage quiet periods to ensure accurate event counting.
- Improved event listener management in tests to prevent memory leaks and ensure proper cleanup.

test(integration): add tests for fixture resolver and storage listener lifecycle

- Implemented tests for the fixture resolver to ensure proper handling of external URLs and locale codes.
- Added tests for the storage listener lifecycle to verify idempotency and cleanup behavior.
@EdgeTypE
EdgeTypE merged commit 358f812 into EdgeTypE:main Jul 17, 2026
3 checks passed
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.

High CPU/memory on idle chat.deepseek.com tab (storage.onChanged firing excessively) Title: UI lag after multiple conversations

2 participants