perf: optimize viewport to skip redundant refreshes#300
perf: optimize viewport to skip redundant refreshes#300
Conversation
Introduces a `_dirty` flag and an optional `force` parameter to the
`viewport.refresh` method. This ensures that the underlying device's
`display` method is only invoked when content has actually changed,
reducing unnecessary I/O and CPU usage.
Changes include:
- Tracking a `_dirty` state when hotspots are removed.
- Adding a `force` flag to `refresh()` to allow explicit overrides.
- Updating `display()` and `set_position()` to trigger a forced
refresh.
- Skipping the `device.display()` call if no redraw is required and no
state changes are detected.
```mermaid
sequenceDiagram
participant App
participant Viewport
participant Hotspot
participant Device
App->>Viewport: refresh(force)
Viewport->>Hotspot: should_redraw()
Hotspot-->>Viewport: redraw_needed
alt force or redraw_needed or dirty
Viewport->>Device: display(image)
Note over Viewport: Set dirty = False
else no changes
Note over Viewport: Skip display update
end
```
Fixes #280
Summary of ChangesHello @rm-hull, 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 significantly enhances the performance of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory 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 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 counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a well-thought-out performance optimization for the viewport class by skipping redundant refreshes. The introduction of a _dirty flag and a force parameter in the refresh method is implemented correctly and logically. The changes ensure that the underlying device's display method is invoked only when necessary, which should reduce I/O and CPU usage as intended. The new test file provides excellent coverage, validating the behavior in various scenarios, including initial state, forced updates, and state changes from hotspot management. The code is clean, and the changes are effective. Overall, this is a high-quality contribution.
Set environment variables to force colored output for tools and disable the interactive `tox` spinner. This improves the readability and cleanliness of the GitHub Actions logs.
This reverts commit f2d5e4c.
Introduces a
_dirtyflag and an optionalforceparameter to theviewport.refreshmethod. This ensures that the underlying device'sdisplaymethod is only invoked when content has actually changed, reducing unnecessary I/O and CPU usage.Changes include:
_dirtystate when hotspots are removed.forceflag torefresh()to allow explicit overrides.display()andset_position()to trigger a forced refresh.device.display()call if no redraw is required and no state changes are detected.sequenceDiagram participant App participant Viewport participant Hotspot participant Device App->>Viewport: refresh(force) Viewport->>Hotspot: should_redraw() Hotspot-->>Viewport: redraw_needed alt force or redraw_needed or dirty Viewport->>Device: display(image) Note over Viewport: Set dirty = False else no changes Note over Viewport: Skip display update endFixes #280