Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

itsjamie
Copy link
Collaborator

@itsjamie itsjamie commented Oct 3, 2022

This PR will...

Reduce CPU time on low-powered devices where these logging calls were taking up a measurable amount of time in the overall profile.

~14.1% of time in a profile spanning multiple segment downloads was spent in getDisplayedText on a Samsung Tizen TV.

Are there any points in the code the reviewer needs to double check?

Standard review.

I tried to limit the changes to the exact calls that would have the highest impact, so anything that required computation to calculate. I left ones that were just constructing new strings alone, because a deeper analysis on string heap collection versus dangling function references would need to be done to know which led to better performance, and ensure no leaks were introduced.

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

This helps reduce CPU time spent parsing 608 captions.
@OrenMe
Copy link
Collaborator

OrenMe commented Oct 4, 2022

@itsjamie hiw does this reduce cpu load? When you say it delays evaluation what does it mean? It seems like this is just passing call site one place down but it is not lazily evaluated in next io loop as far as I can understand.
Also creating a bounded method for a log will inherently add closure so is this really saving up on heap memory?
Would love to get more understanding why this is making things better on low end devices.

@itsjamie
Copy link
Collaborator Author

itsjamie commented Oct 4, 2022

hiw does this reduce cpu load? When you say it delays evaluation what does it mean?

This saves CPU load because we don't need to actually calculate the log message if the verbosity level would mean it would never be printed to the console.

By directly calling the function normally, and passing the string into the log message call, we need to generate that string every invocation rather than when it is actually needed to be printed.

is this really saving up on heap memory?

So, I think on memory usage we only come out positive because the strings are relatively large. Correct that an even better implementation would be a singular bound function rather than an inline definition at each log call, because then we would pay for a single function definition.

@OrenMe
Copy link
Collaborator

OrenMe commented Oct 4, 2022

Thanks @itsjamie, this makes sense.
Why not create a build then that totally removes logger lines? Arguing debugability vs performance, I would say that adding a Babel transform to remove all logs would probably be better than plucking specific log lines for production builds.

@itsjamie
Copy link
Collaborator Author

itsjamie commented Oct 4, 2022

Absolutely, removing logs from the actual build makes a lot of sense. But given it was a large impact, and an easy fix in this one particular case, I felt it was a decent contribution that could help everyone that is using the built distributable directly :)

@robwalch robwalch added this to the 1.3.0 milestone Oct 5, 2022
@robwalch robwalch merged commit 03770fb into master Oct 5, 2022
@robwalch robwalch deleted the feat/delayed-evaluation branch October 5, 2022 22:48
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