Skip to content

Conversation

@viatearz
Copy link
Contributor

@viatearz viatearz commented Aug 4, 2025

It was confirmed that some games suffer from excessive CPU usage.
This is caused by CMMotionManager setting the default update interval to 0, which results in extremely frequent updates.

You can verify the update frequency using the following code:

// NSObject+Swizzle.mm

@implementation NSObject (Swizzle)
- (void)hook_UINSVirtualMotionDevice_scanAccelerometer {
    NSLog(@"[PlayTools] hook_UINSVirtualMotionDevice_scanAccelerometer");
    [self hook_UINSVirtualMotionDevice_scanAccelerometer];
}
@end

@implementation PTSwizzleLoader
+ (void)load {
    [objc_getClass("UINSVirtualMotionDevice") swizzleInstanceMethod:NSSelectorFromString(@"_scanAccelerometer") withMethod:@selector(hook_UINSVirtualMotionDevice_scanAccelerometer)];
}
@end

As shown below, the actual update interval can be as short as 0.0001 seconds.
Screenshot

Some other games explicitly set the update interval to 0.01 or 0.02 seconds via [CMMotionManager setAccelerometerUpdateInterval:], so they do not have excessive CPU usage.

How to Fix
Hook [CMMotionManager init] and change the default update interval to 0.01 seconds.

@viatearz
Copy link
Contributor Author

viatearz commented Aug 4, 2025

Related Games:
#189 Yu-Gi-Oh! Master Duel
PlayCover/PlayCover#1600 Princess Connect Re:Dive(CN)
PlayCover/PlayCover#1832 Ensemble Stars
PlayCover/PlayCover#456 Star Wars: Galaxy of Heroes
GODDESS OF VICTORY: NIKKE
Brown Dust 2
Shadowverse: Worlds Beyond
MementoMori
Solo Leveling: Arise
and many others.

@viatearz viatearz force-pushed the fix/high_cpu_usage branch from 5d22aa6 to dd0002d Compare August 17, 2025 02:33
@TheMoonThatRises
Copy link
Member

If some games explicitly set the update interval, wouldn't it be safer to set this swizzle behind a settings flag?

@viatearz
Copy link
Contributor Author

If some games explicitly set the update interval, wouldn't it be safer to set this swizzle behind a settings flag?

Yes, that would be safer. I will push the changes later.

@TheMoonThatRises TheMoonThatRises linked an issue Sep 12, 2025 that may be closed by this pull request
1 task
@TheMoonThatRises TheMoonThatRises added the enhancement New feature or request label Sep 12, 2025
@viatearz viatearz changed the title Fix high CPU usage issue Fix excessive CPU usage caused by motion sensor updates Sep 13, 2025
@viatearz
Copy link
Contributor Author

All changes submitted.

@TheMoonThatRises TheMoonThatRises merged commit ed9e95d into PlayCover:master Sep 22, 2025
1 check passed
@viatearz viatearz deleted the fix/high_cpu_usage branch October 11, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: excessive CPU usage with playtools - Master Duel - M1 Pro

3 participants