Skip to content
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

fix: improve keybinding performance #4126

Merged
merged 1 commit into from
Oct 29, 2024
Merged

Conversation

Ricbet
Copy link
Member

@Ricbet Ricbet commented Oct 28, 2024

Types

  • 🐛 Bug Fixes

Background or solution

之前是为了解决 rename 的输入框快捷键不展示的问题,而代理 monaco 的 lookupKeybinding 函数,但该函数在遇到非常多 monaco 的实例时(例如 notebook)会有性能问题。
本次修复将该 lookupKeybinding 去除,并使用其他方式解决 rename 的快捷键展示问题

Changelog

改进 keybinding 的性能问题

Summary by CodeRabbit

  • 新特性

    • 引入了新的常量 SKIP_UNREGISTER_MONACO_KEYBINDINGS,用于指定不应注销其默认键绑定的命令。
    • 更新了键绑定注册逻辑,增强了对命令的控制。
  • 变更

    • MonacoServiceImpl 类中的方法进行了更新,部分方法已被弃用,建议使用新的服务注册方法。
  • 错误处理

    • 在打开 URI 时,增强了错误处理机制,确保问题能够被记录和报告。

@Ricbet Ricbet requested review from zhanba, hacke2 and erha19 October 28, 2024 07:53
@Ricbet Ricbet self-assigned this Oct 28, 2024
@Ricbet Ricbet changed the base branch from main to v3.4 October 28, 2024 07:53
@opensumi opensumi bot added the 🐞 bug Something isn't working label Oct 28, 2024
@Ricbet
Copy link
Member Author

Ricbet commented Oct 28, 2024

/next

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Walkthrough

该拉取请求对Monaco编辑器的命令和键绑定处理进行了多项修改。主要更新包括在monaco.contribution.ts中引入了SKIP_UNREGISTER_MONACO_KEYBINDINGS常量,以控制在注册键绑定时哪些命令可以跳过取消注册。monaco.service.ts中的overrideKeybindingResolver方法进行了显著更改,移除了lookupKeybinding功能,并对registerOverridegetOverride方法添加了弃用警告。command.ts中新增了SKIP_UNREGISTER_MONACO_KEYBINDINGS常量,用于指定不应取消注册默认键绑定的命令。

Changes

文件路径 修改摘要
packages/monaco/src/browser/monaco.contribution.ts 添加了SKIP_UNREGISTER_MONACO_KEYBINDINGS,更新了registerKeybindings方法以支持条件取消注册。
packages/monaco/src/browser/monaco.service.ts 移除了lookupKeybinding,更新了registerOverridegetOverride方法以添加弃用警告。
packages/monaco/src/common/command.ts 新增了常量SKIP_UNREGISTER_MONACO_KEYBINDINGS,包含两个字符串元素。

Possibly related PRs

Suggested labels

🐞 bug, ⚙️ refactor

Suggested reviewers

  • bytemain
  • erha19

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/monaco/src/common/command.ts (1)

7-8: 建议完善注释文档

注释说明了常量的用途,但建议补充以下信息:

  • 为什么这些特定命令需要保留默认快捷键
  • 对性能的影响说明

建议更新注释为:

-// 不卸载 Monaco 内默认快捷键的命令白名单
+/**
+ * 保留 Monaco 编辑器默认快捷键的命令白名单。
+ * 这些命令(如重命名相关操作)会保持其原有的快捷键绑定,
+ * 以确保基础编辑功能的正常运行,同时优化多实例场景下的性能表现。
+ */
packages/monaco/src/browser/monaco.contribution.ts (1)

599-607: 优化按键绑定注册逻辑

通过跳过特定命令的按键绑定取消注册过程来提升性能。这个改动:

  1. 避免了不必要的按键绑定取消注册操作
  2. 保持了某些特定命令(如重命名)的原始按键绑定行为

这个改进与 PR 的性能优化目标完全一致。

建议考虑添加注释说明哪些命令会被跳过取消注册以及原因,这样可以帮助其他开发者更好地理解这个优化。

+        // Skip unregistering keybindings for specific commands (e.g. rename) to preserve their original behavior
         if (!SKIP_UNREGISTER_MONACO_KEYBINDINGS.includes(command)) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d7d8a1d and 994d762.

📒 Files selected for processing (3)
  • packages/monaco/src/browser/monaco.contribution.ts (2 hunks)
  • packages/monaco/src/browser/monaco.service.ts (0 hunks)
  • packages/monaco/src/common/command.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/monaco/src/browser/monaco.service.ts
🔇 Additional comments (2)
packages/monaco/src/common/command.ts (1)

8-8: 验证常量使用情况

实现逻辑正确。建议验证此常量在其他模块中的使用情况,确保性能优化的效果。

packages/monaco/src/browser/monaco.contribution.ts (1)

82-82: 导入新的常量以优化按键绑定性能

引入 SKIP_UNREGISTER_MONACO_KEYBINDINGS 常量用于控制哪些命令可以跳过取消注册默认按键绑定的过程,这有助于提高性能。

@opensumi
Copy link
Contributor

opensumi bot commented Oct 28, 2024

🎉 PR Next publish successful!

3.4.5-next-1730102270.0

Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.25%. Comparing base (591891f) to head (994d762).
Report is 1 commits behind head on v3.4.

Additional details and impacted files
@@            Coverage Diff             @@
##             v3.4    #4126      +/-   ##
==========================================
+ Coverage   54.23%   54.25%   +0.02%     
==========================================
  Files        1595     1598       +3     
  Lines       98029    97562     -467     
  Branches    20177    19947     -230     
==========================================
- Hits        53169    52937     -232     
+ Misses      37153    37073      -80     
+ Partials     7707     7552     -155     
Flag Coverage Δ
jsdom 49.81% <100.00%> (+0.09%) ⬆️
node 15.60% <100.00%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants