usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.6k stars 1.27k forks source link

fix: improve masking logic in MaskedEditor for large content handling (fixes #2842) #3472

Closed Pragadesh-45 closed 1 day ago

Pragadesh-45 commented 1 week ago

fixes: #2842

Description

This PR is implemented to improve the app's performance when masking text in the SingleLineEditor. The logic in PR #2240 created a new node for every masked text range. While this logic performs well when the content length is less than 1000 characters, its performance degrades as the length exceeds 1000 characters. In this PR, I've addressed these performance issues.

Changes made:

  1. Added an early return if there are no lines in the editor.
  2. Limited the previous logic to cases where the number of masked characters is less than 500. This is more efficient for editing small content, such as secret environment variables.
  3. For content greater than 500 characters, implemented a line-by-line masking approach to improve performance.

Before:

https://github.com/user-attachments/assets/4b920159-1a16-4a29-b984-c460e5e6bb94

After:

https://github.com/user-attachments/assets/6c63dfea-5d0f-4c79-8e0a-80216c482573

Contribution Checklist:

philippthiele commented 3 days ago

Hi! Following this fix as it really bugs me as well. Was just checking the code fix, why exactly would you differentiate between <500 chars and >=500 chars? I would expect the >=500 chars to work in every situation and for the sake of code simplicity, it should not be handled differently without a very good reason (imho).

Pragadesh-45 commented 3 days ago

Hey @philippthiele,

Thank you for sharing your opinion. While working on this, I noticed that the app's performance was declining when the input exceeded 1000 characters. I realized the need to mask every item individually. I even tried improving performance by storing the positions and applying bulk masking, but it resulted in roughly the same performance.

This led me to consider a different approach: creating a maskedNode for every line to improve performance. However, I noticed that this approach made it difficult to view and edit masked variables side by side, which is useful in many cases, such as editing environment variables.

That’s why I raised a PR with this logic—I just wanted to solve this problem. I’d love to hear your thoughts on it!

philippthiele commented 2 days ago

@Pragadesh-45 thanks for the explanation, it is not a use case I use, but that explains it. Waiting eagerly for this fix to be merged!

Pragadesh-45 commented 2 days ago

Thank you, @philippthiele, for your understanding!

helloanoop commented 1 day ago

Thank you @Pragadesh-45 !