Skip to content

Commit

Permalink
pr feedback, memoize some components
Browse files Browse the repository at this point in the history
  • Loading branch information
chmeyer-ms committed Dec 9, 2024
1 parent 51eb60f commit 909927b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 56 deletions.
7 changes: 4 additions & 3 deletions src/panels/minecraft-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class MinecraftDiagnosticsPanel {
this._statsTracker.setSpeed(message.speed);
break;
default:
console.error('Unknown message type:', message.type);
break;
}
});
Expand Down Expand Up @@ -96,16 +97,16 @@ export class MinecraftDiagnosticsPanel {
}

public static render(extensionUri: Uri, statsTracker: StatsProvider) {
const statsTrackerId = statsTracker.getUniqueId();
const statsTrackerId = statsTracker.uniqueId;
const existingPanel = MinecraftDiagnosticsPanel.activeDiagnosticsPanels.find(
panel => panel._statsTracker.getUniqueId() === statsTrackerId
panel => panel._statsTracker.uniqueId === statsTrackerId
);
if (existingPanel) {
existingPanel._panel.reveal(ViewColumn.One);
} else {
const panel = window.createWebviewPanel(
statsTrackerId,
`Minecraft Diagnostics - [${statsTracker.getName()}]`,
`Minecraft Diagnostics - [${statsTracker.name}]`,
ViewColumn.Active,
{
retainContextWhenHidden: true,
Expand Down
14 changes: 9 additions & 5 deletions src/stats/replay-stats-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ReplayStatsProvider extends StatsProvider {
this._replayFilePath = replayFilePath;
this._replayStreamReader = null;
this._simTickFreqency = this.DEFAULT_SPEED;
this._simTickPeriod = this.MILLIS_PER_SECOND / this._simTickFreqency; // ms per tick
this._simTickPeriod = this._calcSimPeriod(this._simTickFreqency);
this._simTickCurrent = 0;
this._simTimeoutId = null;
this._pendingStats = [];
Expand Down Expand Up @@ -60,7 +60,7 @@ export class ReplayStatsProvider extends StatsProvider {
}
this._replayStreamReader?.close();
this._simTickFreqency = this.DEFAULT_SPEED;
this._simTickPeriod = this.MILLIS_PER_SECOND / this._simTickFreqency;
this._simTickPeriod = this._calcSimPeriod(this._simTickFreqency);
this._simTickCurrent = 0;
this._simTimeoutId = null;
this._pendingStats = [];
Expand Down Expand Up @@ -89,7 +89,7 @@ export class ReplayStatsProvider extends StatsProvider {
if (this._simTickFreqency > this.MAX_SPEED) {
this._simTickFreqency = this.MAX_SPEED;
}
this._simTickPeriod = this.MILLIS_PER_SECOND / this._simTickFreqency;
this._simTickPeriod = this._calcSimPeriod(this._simTickFreqency);
this._fireSpeedChanged();
}

Expand All @@ -98,7 +98,7 @@ export class ReplayStatsProvider extends StatsProvider {
if (this._simTickFreqency < this.MIN_SPEED) {
this._simTickFreqency = this.MIN_SPEED;
}
this._simTickPeriod = this.MILLIS_PER_SECOND / this._simTickFreqency;
this._simTickPeriod = this._calcSimPeriod(this._simTickFreqency);
this._fireSpeedChanged();
}

Expand All @@ -109,7 +109,7 @@ export class ReplayStatsProvider extends StatsProvider {
} else if (this._simTickFreqency > this.MAX_SPEED) {
this._simTickFreqency = this.MAX_SPEED;
}
this._simTickPeriod = this.MILLIS_PER_SECOND / this._simTickFreqency;
this._simTickPeriod = this._calcSimPeriod(this._simTickFreqency);
this._fireSpeedChanged();
}

Expand Down Expand Up @@ -171,4 +171,8 @@ export class ReplayStatsProvider extends StatsProvider {
listener.onPauseUpdated(this._simTimeoutId == null);
});
}

private _calcSimPeriod(simFrequency: number): number {
return this.MILLIS_PER_SECOND / simFrequency;
}
}
42 changes: 22 additions & 20 deletions src/stats/stats-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,39 @@ export interface StatsListener {
}

export class StatsProvider {
private _name: string;
private _uniqueId: string;
protected _statListeners: StatsListener[];

constructor(name: string, id: string) {
this._name = name;
this._uniqueId = id;
constructor(public readonly name: string, public readonly uniqueId: string) {
this._statListeners = [];
}

public getName(): string {
return this._name;
}

public getUniqueId(): string {
return this._uniqueId;
}

public setStats(stats: StatMessageModel) {
for (const stat of stats.stats) {
this._fireStatUpdated(stat, stats.tick);
}
}

public start() {}
public stop() {}
public pause() {}
public resume() {}
public faster() {}
public slower() {}
public setSpeed(speed: string) {}
public start() {
throw new Error('Method not implemented.');
}
public stop() {
throw new Error('Method not implemented.');
}
public pause() {
throw new Error('Method not implemented.');
}
public resume() {
throw new Error('Method not implemented.');
}
public faster() {
throw new Error('Method not implemented.');
}
public slower() {
throw new Error('Method not implemented.');
}
public setSpeed(speed: string) {
throw new Error('Method not implemented.');
}
public manualControl(): boolean {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ const ReplayControls: React.FC<ReplayControlsProps> = ({
);
};

export default ReplayControls;
export default React.memo(ReplayControls);
5 changes: 2 additions & 3 deletions webview-ui/src/home_panel/controls/CommandSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright (C) Microsoft Corporation. All rights reserved.

import React from 'react';
Expand Down Expand Up @@ -54,6 +53,6 @@ const CommandSection: React.FC<CommandSectionProps> = ({
))}
</div>
);
}
};

export default CommandSection;
export default React.memo(CommandSection);
2 changes: 1 addition & 1 deletion webview-ui/src/home_panel/controls/GeneralSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ const GeneralSection: React.FC<GeneralSectionProps> = ({
);
};

export default GeneralSection;
export default React.memo(GeneralSection);
25 changes: 11 additions & 14 deletions webview-ui/src/home_panel/controls/ProfilerSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright (C) Microsoft Corporation. All rights reserved.

import React from 'react';
Expand Down Expand Up @@ -34,7 +33,7 @@ const ProfilerSection: React.FC<ProfilerSectionProps> = ({
onStopProfiler,
isProfilerCapturing,
supportsProfiler,
debuggerConnected
debuggerConnected,
}) => {
return (
<div className="section">
Expand All @@ -44,9 +43,7 @@ const ProfilerSection: React.FC<ProfilerSectionProps> = ({
<VSCodeTextField
type="text"
value={capturesBasePath}
onChange={event =>
onCaptureBasePathEdited(event as React.ChangeEvent<HTMLInputElement>)
}
onChange={event => onCaptureBasePathEdited(event as React.ChangeEvent<HTMLInputElement>)}
className="capture-path-input"
/>
<VSCodeButton className="browse-button" onClick={onCaptureBasePathBrowseButtonPressed}>
Expand All @@ -59,9 +56,9 @@ const ProfilerSection: React.FC<ProfilerSectionProps> = ({
onClick={isProfilerCapturing ? onStopProfiler : onStartProfiler}
disabled={!debuggerConnected || !supportsProfiler || capturesBasePath === ''}
>
{isProfilerCapturing ? "Stop Profiler" : "Start Profiler"}
{isProfilerCapturing ? 'Stop Profiler' : 'Start Profiler'}
</VSCodeButton>
<div className={`profiler-spinner ${isProfilerCapturing ? "profiler-spinner-spinning" : ""}`}></div>
<div className={`profiler-spinner ${isProfilerCapturing ? 'profiler-spinner-spinning' : ''}`}></div>
</div>
<h4 className={`sub-title ${captureItems.length === 0 ? 'hidden' : ''}`}>Captures</h4>
<div
Expand All @@ -71,17 +68,17 @@ const ProfilerSection: React.FC<ProfilerSectionProps> = ({
{captureItems.map(captureItem => (
<div
key={captureItem.fileName}
className={`capture-item ${selectedCaptureItem?.fileName === captureItem.fileName ? 'capture-item-selected' : ''}`}
className={`capture-item ${
selectedCaptureItem?.fileName === captureItem.fileName ? 'capture-item-selected' : ''
}`}
onClick={() => onSelectCaptureItem(captureItem)}
>
<span>
{captureItem.fileName}
</span>
<span>{captureItem.fileName}</span>
<button
className="capture-item-delete-button"
onClick={(event) => {
onClick={event => {
event.stopPropagation();
onDeleteCaptureItem(captureItem)
onDeleteCaptureItem(captureItem);
}}
>
Delete
Expand All @@ -93,4 +90,4 @@ const ProfilerSection: React.FC<ProfilerSectionProps> = ({
);
};

export default ProfilerSection;
export default React.memo(ProfilerSection);
13 changes: 4 additions & 9 deletions webview-ui/src/home_panel/controls/StatusSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright (C) Microsoft Corporation. All rights reserved.

import React from 'react';
Expand All @@ -7,17 +6,13 @@ interface StatusSectionProps {
debuggerConnected: boolean;
}

const StatusSection: React.FC<StatusSectionProps> = ({
debuggerConnected
}) => {
const StatusSection: React.FC<StatusSectionProps> = ({ debuggerConnected }) => {
return (
<div className="status-container">
<div
className={`status-circle ${debuggerConnected ? 'active' : 'inactive'}`}
></div>
<div className={`status-circle ${debuggerConnected ? 'active' : 'inactive'}`}></div>
{debuggerConnected ? 'Minecraft Connected' : 'Minecraft Disconnected'}
</div>
);
}
};

export default StatusSection;
export default React.memo(StatusSection);

0 comments on commit 909927b

Please sign in to comment.