Perf(custom): add memory monitor and optimiz memory usage

This commit is contained in:
Kuingsmile
2025-08-13 15:11:55 +08:00
parent 11341c024a
commit f0b0e55937
7 changed files with 144 additions and 79 deletions

View File

@@ -62,8 +62,8 @@ const trayWindowOptions = {
preload: preloadPath,
nodeIntegration: false,
contextIsolation: true,
nodeIntegrationInWorker: true,
backgroundThrottling: false,
nodeIntegrationInWorker: false,
backgroundThrottling: true,
webSecurity: false
}
}
@@ -83,11 +83,11 @@ const settingWindowOptions = {
webPreferences: {
sandbox: false,
webviewTag: true,
backgroundThrottling: false,
backgroundThrottling: true,
preload: preloadPath,
nodeIntegration: false,
contextIsolation: true,
nodeIntegrationInWorker: true,
nodeIntegrationInWorker: false,
webSecurity: false
}
} as IBrowserWindowOptions
@@ -112,8 +112,8 @@ const miniWindowOptions = {
preload: preloadPath,
nodeIntegration: false,
contextIsolation: true,
backgroundThrottling: false,
nodeIntegrationInWorker: true
backgroundThrottling: true,
nodeIntegrationInWorker: false
}
} as IBrowserWindowOptions
@@ -133,7 +133,7 @@ const renameWindowOptions = {
preload: preloadPath,
nodeIntegration: false,
contextIsolation: true,
nodeIntegrationInWorker: true,
nodeIntegrationInWorker: false,
backgroundThrottling: false
}
} as IBrowserWindowOptions
@@ -158,11 +158,11 @@ const toolboxWindowOptions = {
icon: logo,
webPreferences: {
sandbox: false,
backgroundThrottling: false,
backgroundThrottling: true,
preload: preloadPath,
nodeIntegration: false,
contextIsolation: true,
nodeIntegrationInWorker: true,
nodeIntegrationInWorker: false,
webSecurity: false
}
} as IBrowserWindowOptions

View File

@@ -1,5 +1,31 @@
import { EventEmitter } from 'node:events'
const bus = new EventEmitter()
export default bus
import { EventEmitter } from 'node:events'
class OptimizedBus extends EventEmitter {
constructor () {
super()
this.setMaxListeners(50)
}
once (event: string | symbol, listener: (...args: any[]) => void): this {
const wrappedListener = (...args: any[]) => {
try {
listener(...args)
} finally {
this.removeListener(event, wrappedListener)
}
}
return super.once(event, wrappedListener)
}
cleanupListeners () {
const events = this.eventNames()
events.forEach(event => {
const listenerCount = this.listenerCount(event)
console.log(` listener count (${listenerCount}) for event: ${String(event)}`)
})
}
}
const bus = new OptimizedBus()
export default bus