-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor: improve the fluency when dragging and dropping nodes in batches using manhattan router #4979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ches using manhattan router
Summary of ChangesHello @GaoFuhong, 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! 此拉取请求旨在显著提升在使用曼哈顿路由时批量拖拽节点的流畅性。通过引入共享障碍图缓存机制,减少了不必要的重复计算;同时,将路由算法中的开放集数据结构从排序数组优化为二叉堆,大幅提高了路径查找的效率。此外,为解决批量拖拽时频繁路由计算导致的卡顿问题, Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 旨在通过共享 ObstacleMap 缓存、使用二叉堆优化开放集以及在批量拖拽时进行路由降级等方式,优化曼哈顿路由在批量拖拽节点时的性能和流畅性。代码改动清晰地实现了这些优化目标,特别是 SortedSet 的重构和 ObstacleMap 的缓存机制,对性能提升有显著帮助。文档和测试用例也得到了相应的更新,覆盖了新功能。
我在代码中发现了一个可能导致缓存失效的严重问题,并提出了一些关于性能和代码可维护性的改进建议,希望能帮助进一步提升代码质量。
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4979 +/- ##
==========================================
+ Coverage 82.72% 83.21% +0.48%
==========================================
Files 334 334
Lines 38186 38390 +204
Branches 7756 7858 +102
==========================================
+ Hits 31591 31946 +355
+ Misses 6572 6421 -151
Partials 23 23
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 进行了几项重要的性能优化,显著提升了在使用曼哈顿路由时批量拖拽节点的流畅度。
主要改动包括:
- 将
SortedSet实现从排序数组改为二叉堆:这是一个核心的算法改进,将add/pop操作的时间复杂度从 O(n) 降低到 O(log n),极大地提升了路由寻路的效率。 - 共享并缓存
ObstacleMap:通过WeakMap为每个Model实例缓存ObstacleMap,并利用事件监听机制实现缓存失效,有效避免了在同一帧内为每条边重复构建障碍物地图的问题。 - 拖拽时路由降级:新增了
movingRouterFallback选项,允许在批量拖拽节点时临时将高消耗的manhattan路由降级为轻量的orth路由,减少了拖拽过程中的计算量,提升了交互的流畅性。
代码实现质量很高,新功能也配备了相应的文档和单元测试。我只发现了一个关于代码清晰度的小问题,具体请看我的评论。
整体来看,这是一次非常出色的重构和性能优化!
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 围绕曼哈顿路由在批量拖拽节点时的性能问题进行了重构和优化,整体质量非常高。主要改动包括:共享 ObstacleMap 缓存、将路由开放集改为二叉堆、以及增加了拖拽过程中的路由降级策略。这些改动设计精良,实现稳健,显著提升了性能和用户体验。同时,相关的文档和测试也得到了相应的更新。
我发现了一些可以改进的小地方:一处文档示例代码可以更清晰,以及一处缓存失效逻辑中存在冗余的事件监听。具体细节请查看我的评论。
| model.on('node:change:position', () => markDirty(model)) | ||
| model.on('node:change:size', () => markDirty(model)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Description
优化了在使用曼哈顿路由时批量拖拽节点卡顿的问题:
🖼️ Screenshot
💡 Motivation and Context
🧩 Types of changes
🔍 Self Check before Merge