WindowServer The main task is to draw graphics-related things for macOS, which means everything you can see from the whole screen, you have to go through WindowServer and let it draw for you.
There are many reasons WindowServer uses a high processor.
- You have complex drawing methods in the application. - Try to simplify your drawing method.
- You have a lot of graphics on your desktop so that WindowServer not only draws your application, but also desktop graphics. - Try cleaning the desktop.
- Do you have applications that require complex graphic drawing? - Try closing this application.
Until you see your exact code, I cannot tell you why placing elements in a separate window can help. Perhaps the window itself hides something that makes drawing easier?
One of my programs has a lot of graphic elements and animations. But I never came across your problem. How about creating a test project and trying things like that? Sometimes this can help to see a problem with a clearer project structure.
I created a simple demo that has 100 * 100 sublayers in the window. There seems to be no problem.
import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet weak var window: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application self.window.contentView?.wantsLayer = true let size = 10 for i in 0..<10000 { let x = i%100 let y = i/100 let layer = CALayer() layer.frame = NSRect(x: x*size, y: y*size, width: size, height: size) layer.backgroundColor = .random() self.window.contentView?.layer?.addSublayer(layer) } } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } } extension CGFloat { static func random() -> CGFloat { return CGFloat(arc4random()) / CGFloat(UInt32.max) } } extension CGColor { static func random() -> CGColor { return CGColor(red: .random(), green: .random(), blue: .random(), alpha: 1.0) } }

source share