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

Proposal to improve performance of setEnvVariables() (37! tccd uses 3% CPU continuously) #362

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/common/classes/XDisplayRefreshRateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as fs from "fs";
export class XDisplayRefreshRateController {
private displayName: string;
private isX11: boolean;
private dataIsFresh: boolean;
private displayEnvVariable: string;
private xAuthorityFile: string;
public XDisplayRefreshRateController() {
Expand All @@ -31,10 +32,22 @@ export class XDisplayRefreshRateController {
}

private setEnvVariables(): void {
if(this.dataIsFresh){
return;
}
const output = child_process
.execSync(
`ps -u $(id -u) -o pid= | xargs -I{} cat /proc/{}/environ 2>/dev/null | tr '\\0' '\\n'`
)
.execSync(`
ps -u $(id -u) -o pid= | \
tail --lines 20 | \
xargs -I{} cat /proc/{}/environ 2>/dev/null | \
tr '\\0' '\\n' | \
awk '
/DISPLAY=/ && !countDisplay {print; countDisplay++}
/XAUTHORITY=/ && !countXAuthority {print; countXAuthority++}
/XDG_SESSION_TYPE=/ && !countSessionType {print; countSessionType++}
{if (countDisplay && countXAuthority && countSessionType) exit}
'
`)
.toString();

const displayMatch = output.match(/^DISPLAY=(.*)$/m);
Expand Down Expand Up @@ -66,6 +79,9 @@ export class XDisplayRefreshRateController {
: sessionType === "wayland"
? false
: undefined;

this.dataIsFresh = true;
setTimeout(() => this.dataIsFresh = false, 60_000)
}

public getIsX11(): boolean {
Expand Down