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

Investigate extension energy consumption anomalies #557

Open
ACTCD opened this issue Oct 15, 2023 · 9 comments
Open

Investigate extension energy consumption anomalies #557

ACTCD opened this issue Oct 15, 2023 · 9 comments
Labels
maintenance Chores and refactoring
Milestone

Comments

@ACTCD
Copy link
Collaborator

ACTCD commented Oct 15, 2023

There is a review in the App Store:

调用safari的时候插件能耗激增
评论人:comet111111 – 2023年10月11日
mac sonoma,从其他程序转到safari的时候,插件的能耗瞬间增长到600 ,之后恢复正常。工作过程中需要频繁在其他程序和safari之间跳转,导致耗电明显加快

The user reported that in v4.4.4, possibly after the improvement of #525, they found that the energy consumption was abnormal when switching to Safari, and the energy consumption value in the activity monitor reached 600.

Initial local testing, however, was unable to reproduce the problem, and even with multiple tests containing nearly 20 scripts, the energy consumption value topped out at just around 10. In all other operations, the peak energy consumption hardly exceeds 200.

Since the user does not provide specific usage scenarios, and contextual information such as script type and number, it is not possible to target debugging and reproduce the problem. However, this issue is recorded here if we have the opportunity to be able to get more information or to keep an eye on and investigate the issue, as well as look for ways and spaces for improvement.

@0f7b90
Copy link

0f7b90 commented Oct 20, 2023

Hello, this user is me. Thank you for paying attention to this issue.
I added about 10 scripts, and after my troubleshooting, it was the following script that caused the problem (the same is true of disabling it, and returning to normal after deleting it):
https://greasyfork.org/scripts/370246-sci-hub-button/code/Sci-hub%20button.user.js

(In addition, I noticed that Userscripts also triggers 20-40% resource consumption when opening a Web page that doesn't require calling scripts. I don't know if this is a normal expectation.)

@ACTCD
Copy link
Collaborator Author

ACTCD commented Oct 20, 2023

It looks like the script has a fairly large header, but I'm still not sure exactly what's causing the problem and will require further in-depth investigation and debugging.

But to answer your second question first, due to the way the extension works, on every page load it injects the content script and checks if there is any user script that needs to be injected, so it still requires some resources.

But I'm not sure what you mean by "20-40% resource"?

@0f7b90
Copy link

0f7b90 commented Oct 21, 2023

Maybe my expression is wrong. It’s the “Impact on energy consumption” value in Activity Monitor. I don’t know which unit should be used to express it.

@ACTCD
Copy link
Collaborator Author

ACTCD commented Oct 21, 2023

@CometYZ OK, I see, thanks for the clarification.

@ACTCD
Copy link
Collaborator Author

ACTCD commented Oct 21, 2023

@CometYZ Hello, I have used the script you provided for repeated local testing, but the abnormal energy consumption still cannot be reproduced. After installing the script, the energy consumption value increased, but still could not exceed 20.

More specifically, while repeatedly switching the focus between Safari and the activity monitor, this action reflecting an energy consumption value of the extension just around 10-20. But Safari itself has an energy consumption value of about 200-300 (even if I completely disable the extension), which is comparable to the Activity Monitor itself.

However, I can observe higher values when scrolling this script up and down in the editor of the extension page, with peaks that can exceed 1000. (But I don't think that's the scene you're talking about.)

For reference, can you provide a screen recording showing your observation process? It would be best to include changes in the overall energy consumption of the Extension, Safari, and Activity Monitor itself.

@0f7b90
Copy link

0f7b90 commented Oct 21, 2023

https://drive.google.com/file/d/1mQ6jYM07bw6YQGIuX9YmYUbHUCe4ZHDw/view?usp=share_link
By the way, my computer is Macbook Air M1 Sonoma 14.0, which turns on the Stage Manager.

@ACTCD
Copy link
Collaborator Author

ACTCD commented Oct 21, 2023

@CometYZ Thank you for the information. Now I know, I was observing the wrong process. And yes, I can reproduce the same or even higher values ​​than you.

I believe this is the correct rendering. Based on my previous brief speculation, due to the large size of the script (head and body), it would take proportionately more resources to parse it each time.

Compared with instantaneous energy impact value, I believe that CPU Time is a more intuitive and obvious reference value.

All things considered, there's probably no easy way around this without breaking existing functionality and experience. To completely solve this problem, overall process optimization is required to reduce the calculations required in each process. This means a lot of refactoring work, some of which we are also working on.

However, thank you for your feedback on this issue, which will serve as one of the important reference standards for our subsequent reconstruction work.

@0f7b90
Copy link

0f7b90 commented Oct 21, 2023

Got it. Thank you for the answer!

@ACTCD
Copy link
Collaborator Author

ACTCD commented Nov 11, 2023

I think I've come up with a way to quickly ease the calculations by checking when the file was last updated, rather than parsing its contents each time.

But this means some structural changes and relies on another issue that needs improvement.

Just recording this idea, I will try and reconstruct it in the near future.

@ACTCD ACTCD added this to the v6.0.0 milestone Apr 17, 2024
@ACTCD ACTCD added enhancement Feature work maintenance Chores and refactoring and removed enhancement Feature work labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Chores and refactoring
Projects
None yet
Development

No branches or pull requests

2 participants