Skip to content

Commit

Permalink
Merge pull request #449 from NordicSemiconductor/performace-improvments
Browse files Browse the repository at this point in the history
Performance improvements
  • Loading branch information
kylebonnici authored Apr 2, 2024
2 parents 9a5430f + 0dab407 commit b37b754
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 41 deletions.
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 4.0.1 - UNRELEASED

### Changed

- Moved feedback tab to a dialog which can be opened by going to the about tab
and click **Give Feedback**

### Fixed

- Chart frame trotting for slower machines

## 4.0.0 - 2024-03-13

### Added
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pc-nrfconnect-ppk",
"version": "4.0.0",
"version": "4.0.1",
"displayName": "Power Profiler",
"description": "App for use with Nordic Power Profiler Kits",
"homepage": "https://github.com/NordicSemiconductor/pc-nrfconnect-ppk",
Expand Down Expand Up @@ -47,13 +47,13 @@
"nordic-publish": "node ./dist/nordic-publish.js"
},
"devDependencies": {
"@nordicsemiconductor/pc-nrfconnect-shared": "^167.0.0",
"@nordicsemiconductor/pc-nrfconnect-shared": "^170.0.0",
"@types/archiver": "^6.0.2",
"@types/fs-extra": "^11.0.4",
"@types/redux-mock-store": "^1.0.3",
"@types/unzipper": "^0.10.9",
"bson": "4.6.5",
"chart.js": "^4.3.3",
"chart.js": "^4.4.2",
"mathjs": "^10.6.3",
"react-chartjs-2": "^5.2.0",
"redux-mock-store": "^1.5.4",
Expand Down
11 changes: 8 additions & 3 deletions src/actions/deviceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,18 @@ export const open =

clearInterval(updateRequestInterval);
let renderIndex: number;
let lastRenderRequestTime = 0;
updateRequestInterval = setInterval(() => {
const now = Date.now();
if (
renderIndex !== DataManager().getTotalSavedRecords() &&
getState().app.app.samplingRunning &&
isDataLoggerPane(getState())
isDataLoggerPane(getState()) &&
(DataManager().isInSync() ||
now - lastRenderRequestTime >= 1000) // force 1 FPS
) {
const timestamp = Date.now();
const timestamp = now;
lastRenderRequestTime = now;
if (getState().app.chart.liveMode) {
requestAnimationFrame(() => {
/*
Expand All @@ -423,7 +428,7 @@ export const open =
});
renderIndex = DataManager().getTotalSavedRecords();
}
}, 30);
}, Math.max(30, DataManager().getSamplingTime() / 1000));
};

export const updateRegulator =
Expand Down
8 changes: 0 additions & 8 deletions src/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,12 @@ const Chart = () => {
}
}, [xAxisMax]);

const lastLiveRenderTime = useRef<number>(0);
const lastFPSUpdate = useRef<number>(performance.now());
const fpsCounter = useRef<number>(0);

useEffect(() => {
const now = performance.now();
const forceRender = now - lastLiveRenderTime.current > 1000; // force 1 FPS
if (liveMode) {
if (!DataManager().isInSync() && !forceRender) {
return;
}

lastLiveRenderTime.current = now;

nextUpdateRequests = () => {
fpsCounter.current += 1;
return updateChart(
Expand Down
16 changes: 12 additions & 4 deletions src/components/SaveExport/ExportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
*/

import React, { useEffect, useMemo, useRef, useState } from 'react';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import ProgressBar from 'react-bootstrap/ProgressBar';
import { useDispatch, useSelector } from 'react-redux';
import { dialog, getCurrentWindow } from '@electron/remote';
Expand Down Expand Up @@ -149,12 +155,14 @@ export default () => {
.replace('u', '\u00B5')
);
}, [duration]);
const filename = createFileName();
const close = () => {

const close = useCallback(() => {
cancel.current = true;
dispatch(hideExportDialog());
};
}, [dispatch]);

const saveFile = async () => {
const filename = createFileName();
const { filePath: fn } = await dialog.showSaveDialog(
getCurrentWindow(),
{
Expand Down
1 change: 1 addition & 0 deletions src/features/minimap/Minimap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ function initializeMinimapChart(
],
},
options: {
parsing: false,
animation: false,
layout: {
autoPadding: false,
Expand Down
20 changes: 9 additions & 11 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const initialSamplesPerSecond = 1e6 / initialSamplingTime;
export const microSecondsPerSecond = 1e6;

const tempBuffer = new Uint8Array(6);
const tempView = new DataView(tempBuffer.buffer);

export interface GlobalOptions {
/** The number of samples per second */
samplesPerSecond: number;
Expand Down Expand Up @@ -174,21 +176,18 @@ export const DataManager = () => ({
getTimestamp,
isInSync: () => {
const actualTimePassed =
performance.now() -
Date.now() -
(options.writeBuffer?.getFirstWriteTime() ??
options.fileBuffer?.getFirstWriteTime() ??
0);
const simulationDelta = getTimestamp() / 1000;
if (simulationDelta > actualTimePassed) return true;

const pcAheadDelta = actualTimePassed - simulationDelta;
if (
pcAheadDelta >
Math.max(30, getSamplingTime(options.samplesPerSecond) * 1.5)
) {
return false;
}
return true;

// We get serial data every 30 ms regardless of sampling rate.
// If PC is ahead by more then 1.5 samples we are not in sync
return pcAheadDelta <= 45;
},
getStartSystemTime: () => options.fileBuffer?.getFirstWriteTime(),

Expand All @@ -199,9 +198,8 @@ export const DataManager = () => ({
)
return;

const view = new DataView(tempBuffer.buffer);
view.setFloat32(0, current, true);
view.setUint16(4, bits);
tempView.setFloat32(0, current, true);
tempView.setUint16(4, bits);

if (options.writeBuffer) {
options.writeBuffer.append(tempBuffer);
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ render(
appReducer={reducers}
deviceSelect={<DeviceSelector />}
sidePanel={<SidePanel />}
feedback
documentation={DocumentationSections}
panes={[
{ name: 'Data Logger', Main: ChartWrapper },
Expand Down

0 comments on commit b37b754

Please sign in to comment.