Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Mar 31, 2025

Avoid lagging during multi window preview.

Summary by Sourcery

Optimize window preview fetching for X11 using map-reduce concurrency to improve performance and reduce lag during multi-window preview

Enhancements:

  • Implement concurrent window preview fetching using QtConcurrent::blockingMapped to parallelize preview generation

Build:

  • Add Qt Concurrent library as a link dependency in CMakeLists.txt

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 31, 2025

Reviewer's Guide by Sourcery

This pull request introduces a map-reduce approach using QtConcurrent::blockingMapped to fetch window previews in parallel. This change aims to reduce UI lag when generating previews for multiple windows. Additionally, the QtConcurrent module was added to the CMakeLists.txt file.

Sequence diagram for fetching window previews with map-reduce

sequenceDiagram
  participant AppItemWindowModel
  participant AbstractWindow
  participant X11Preview

  AppItemWindowModel->>AppItemWindowModel: m_previewPixmaps.clear()
  alt m_item is not null
    loop for each window in m_item->getAppendWindows()
      AppItemWindowModel->>X11Preview: fetchWindowPreview(window->id())
      activate X11Preview
      X11Preview-->>AppItemWindowModel: previewPixmap
      deactivate X11Preview
      AppItemWindowModel->>AppItemWindowModel: Store previewPixmap in m_previewPixmaps
    end
  end
Loading

Updated class diagram for AppItemWindowModel

classDiagram
  class AppItemWindowModel {
    -QHash<uint32_t, QPixmap> m_previewPixmaps
    +void updatePreviewPixmaps()
    -QPixmap fetchWindowPreview(uint32_t windowId)
  }
  note for AppItemWindowModel "Uses QtConcurrent::blockingMapped to fetch previews in parallel"
Loading

File-Level Changes

Change Details Files
Implemented a map-reduce approach using QtConcurrent::blockingMapped to fetch window previews in parallel, aiming to reduce UI lag during multi-window preview generation.
  • Utilized QtConcurrent::blockingMapped to concurrently process the list of windows.
  • The lambda function passed to blockingMapped captures the this pointer to allow access to the fetchWindowPreview method.
  • The result of blockingMapped is a list of QPair<uint32_t, QPixmap>, where the first element is the window ID and the second is the corresponding preview pixmap.
  • The resulting pairs are then iterated over to insert the window ID and pixmap into the m_previewPixmaps map.
  • Added Qt${QT_VERSION_MAJOR}::Concurrent to the target link libraries in CMakeLists.txt.
panels/dock/taskmanager/x11preview.cpp
panels/dock/taskmanager/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @18202781743 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding some error handling or logging within the lambda function to handle cases where fetchWindowPreview might fail.
  • It might be worth benchmarking the performance improvement to quantify the reduction in lag.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Avoid lagging during multi window preview.
@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • CMakeLists.txt文件中新增了Qt${QT_VERSION_MAJOR}::Concurrent库的链接,需要确认是否有必要,以及是否已经正确配置了并发模块的依赖。
  • x11preview.cpp文件中重新组织了头文件的包含顺序,这有助于提高代码的可读性,但应确保新的包含顺序不会影响编译或运行时性能。
  • AppItemWindowModel类中使用了QtConcurrent::blockingMapped来并行处理窗口预览的获取,这可以提升性能,但需要确保并行处理不会引入线程安全问题。

是否建议立即修改:

  • 是,特别是对于并发处理和库链接的修改,需要确保它们不会引入新的问题。对于头文件的重新组织,建议立即修改以提高代码质量。

@18202781743 18202781743 changed the title improve: using map-reduce to fetch window preview for x11 pref: using map-reduce to fetch window preview for x11 Mar 31, 2025
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 31, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 499e14a into linuxdeepin:master Mar 31, 2025
7 of 10 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.

3 participants