Skip to content

Commit

Permalink
fix(graphing): Low FPS due to the deduplication of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed Dec 10, 2023
1 parent 76e644a commit 45b68d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/compiler/token/RootToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { TokenType } from "@/compiler/token/Token";
export default class RootToken extends ChildrenToken {
public readonly type: TokenType = TokenType.ROOT;

/**
* We cannot clone an object with function(s) to pass it
* to a worker, so a root token cloned and passed to a
* worker should be put into this `create()` method to
* let it be transformed into an object with function(s).
*/
public static create(rootObject: RootToken): RootToken {
return new RootToken(rootObject.value);
}
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/Render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export default class Render {
Render.colors.highlight = "#fff";
}

/**
* Messaging between rendering thread and calculating thread
*
* Rendering thread: @/workers/graphing.worker.ts
* Calculating thread: @/workers/calculating.worker.ts
*/
private handleCalculatingWorkerMessaging(e: MessageEvent): void {
const res = e.data;

Expand Down
2 changes: 0 additions & 2 deletions src/utils/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import List from "@/utils/List";
export default class Collection<T = any> extends List<T> {
public override add(item: T): void {
this.value.push(item);
this.deduplicate();
}

public unshift(item: T): void {
this.value.unshift(item);
this.deduplicate();
}

public shift(): T | undefined {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export default class List<T = any> {
return -1;
}

public deduplicate(): void {
this.value = [...new Set(this.value)];
}
// public deduplicate(): void {
// this.value = [...new Set(this.value)];
// }

public equals(list: List): boolean {
return Utils.arrayIs(this.value, list.value);
Expand Down

1 comment on commit 45b68d7

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.