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

[Eco Mode] High CPU usage while train station is selected #15

Open
yne opened this issue Jan 2, 2022 · 0 comments
Open

[Eco Mode] High CPU usage while train station is selected #15

yne opened this issue Jan 2, 2022 · 0 comments

Comments

@yne
Copy link

yne commented Jan 2, 2022

While using the Eco Mode, the map rendering only use 14%, which is very nice !

However, when a train is selected and the bottom train-panel shows up, the CPU usage goes (and stay) at 60%.

The issue seems to be related to this glowing animation on the station "circle" :
image

const repeat = () => {
const {height} = bodyElement.getBoundingClientRect(),
{timetableIndex: index} = train,
curr = timetableOffsets[index],
next = train.arrivalStation ? timetableOffsets[index + 1] : curr,
y = lerp(curr, next, train._t),
p = performance.now() % 1500 / 1500;
container.querySelector('#train-mark').innerHTML =
`<circle cx="22" cy="${y + 10}" r="${7 + p * 15}" fill="#ffffff" opacity="${1 - p}" />` +
`<circle cx="22" cy="${y + 10}" r="7" fill="#ffffff" />`;
if (scrollTop === undefined || scrollTop === bodyElement.scrollTop) {
bodyElement.scrollTop = Math.round(y - height / 2 + 4);
scrollTop = bodyElement.scrollTop;
}
if (me._container) {
requestAnimationFrame(repeat);
}
};

This animation querySelect and update the existing "circle" with a new SVG element on every frame.

Possible solutions:

  • Slow down the animation according to the "Eco Mode" instead of every requestAnimationFrame
  • Replace the animation with a more "static" design (for example a colored outline)
  • Use a CSS animation: glow 2s steps(2) infinite; with a GPU-friendly attribute (opacity, translate3d ...)

If you don't have time, I can Pull Request you a fix.

PS: They are others animations, that are redrawn 60 times / sec (but they are less CPU intensive, so it's okay)

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

No branches or pull requests

1 participant