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 player position performance issue #606

Merged
merged 1 commit into from Aug 1, 2023

Conversation

karniv00l
Copy link
Contributor

@karniv00l karniv00l commented Aug 1, 2023

Fixes #507

I'm not sure whether this is a correct fix and why it's not present on all platforms, devtools show re-renders every tick:

Screenshot 2023-08-01 at 08 45 10

After this fix, when the song is playing, re-render only happens ever 1s (update freq of the position slider), when the song is stopped - zero re-renders

@@ -48,7 +48,6 @@ class PlayerControls extends HookConsumerWidget {

final playing =
useStream(audioPlayer.playingStream).data ?? audioPlayer.isPlaying;
final buffering = useStream(audioPlayer.bufferingStream).data ?? true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no clue why, but this is also causing re-renders

@@ -89,215 +88,208 @@ class PlayerControls extends HookConsumerWidget {
iconSize: compact ? 18 : 24,
);

return RepaintBoundary(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only RepaintBoundary and buffering removed

@@ -62,99 +62,95 @@ class PlayerOverlay extends HookConsumerWidget {
child: AnimatedOpacity(
duration: const Duration(milliseconds: 250),
opacity: canShow ? 1 : 0,
child: RepaintBoundary(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only RepaintBoundary removed

// Duration future is needed for getting the duration of the song
// as stream can be null when no event occurs (Mostly needed for android)
final durationFuture = useFuture(audioPlayer.duration);
Copy link
Contributor Author

@karniv00l karniv00l Aug 1, 2023

Choose a reason for hiding this comment

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

both useFutures cause hook to re-create every tick

@@ -9,21 +8,29 @@ import 'package:spotube/services/audio_player/audio_player.dart';
Duration duration,
double bufferProgress
}) useProgress(WidgetRef ref) {
final playlist = ref.watch(ProxyPlaylistNotifier.provider);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused

@RaptaG RaptaG added bug Something isn't working UI A suggestion/bug report of a UI element labels Aug 1, 2023
@RaptaG RaptaG requested a review from KRTirtho August 1, 2023 10:02
@KRTirtho
Copy link
Owner

KRTirtho commented Aug 1, 2023

That's awesome work 🚀. Let me quickly check

@KRTirtho
Copy link
Owner

KRTirtho commented Aug 1, 2023

The CPU usage has dramatically reduced now 🚀
Left - Changed (Task Manager 2nd) |||| Right - Old Version (Task Manager 1st)
image

@KRTirtho
Copy link
Owner

KRTirtho commented Aug 1, 2023

This is when all music is paused
image

@KRTirtho KRTirtho merged commit 3e0834f into KRTirtho:dev Aug 1, 2023
@karniv00l karniv00l deleted the fix-performance branch August 1, 2023 13:47
meenbeese pushed a commit to meenbeese/spotube that referenced this pull request Sep 20, 2023
meenbeese pushed a commit to meenbeese/spotube that referenced this pull request Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working UI A suggestion/bug report of a UI element
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants