Skip to content

Conversation

@nilscb
Copy link
Collaborator

@nilscb nilscb commented May 5, 2025

Added a component to show metrics from deck.gl (like frames pr sec etc)
Demonstrated in story Map/BigMap3D

@nilscb nilscb linked an issue May 5, 2025 that may be closed by this pull request
@nilscb nilscb self-assigned this May 5, 2025
@nilscb nilscb added enhancement New feature or request AspenTech Task owned by AspenTech labels May 5, 2025
@nilscb nilscb requested a review from w1nklr May 5, 2025 14:02
Copy link
Collaborator

@w1nklr w1nklr left a comment

Choose a reason for hiding this comment

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

I (with my current react knowledge) am wondering about this usage of ref/imperative handle.
I don't know all the benefits/drawbacks, but I feel it's a bit overkill for the need.

Curious, I checked and currently found only 1 (resp. 2) usage of forwardRef (resp. useImperativeHandle) in Deck.gl repo, 0 (resp. 1) in webviz and about 15 (I did not count duplicated code) (resp. 0) in the whole NGR code.

@nilscb
Copy link
Collaborator Author

nilscb commented May 7, 2025

The reason for using forward ref etc is that I want only the metrics component to redraw when a new metrics update occurs. Alternatively it could be a state in the story component and the metrics info could be sent to the metrics component trough a property. However that would cause also the deck component to redraw which is undesirable. But this rest on my understanding that if a react components state is changed then all its children will also be redrawn, I could be wrong here (Håvard disagrees I think) I don't have any strong feelings about it but redrawing deck may alter its statistics which is the very thing we want to measure.

Copy link
Collaborator

@w1nklr w1nklr left a comment

Choose a reason for hiding this comment

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

Let's discuss the forwardref/imperative handle with @hkfb .

Testing if other approach forces a redraw will be easy: this would cause endless rendering, wouldn't it ?

@w1nklr
Copy link
Collaborator

w1nklr commented May 14, 2025

Here a snapshot:
image

@w1nklr w1nklr requested a review from hkfb May 15, 2025 07:42
Comment on lines +103 to +107

/**
* Callback called from deck.gl whith metrics data.
*/
onMetrics?: ((m: DeckMetrics) => void) | null;
Copy link
Collaborator

@hkfb hkfb May 15, 2025

Choose a reason for hiding this comment

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

Not needed, since MapProps is already included in the type definition.

lights,
children,
verticalScale,
onMetrics,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not needed, should be included in ...args

triggerResetMultipleWells={triggerResetMultipleWells}
lights={lights}
verticalScale={verticalScale}
onMetrics={onMetrics ?? undefined}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not needed, should be included in ...args

/**
* Callback called from deck.gl whith metrics data.
*/
onMetrics?: ((m: DeckMetrics) => void) | null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest using something like DeckGL["_onMetrics"], so that we don't need to duplicate the type

Comment on lines +331 to +345
const metricsComponentRef = React.useRef<{
updateMetrics?: (m: DeckMetrics) => void;
} | null>(null);
const updateMetrics = (m: DeckMetrics) => {
if (!metricsComponentRef.current) {
return;
}
if ("updateMetrics" in metricsComponentRef.current) {
metricsComponentRef.current.updateMetrics?.(m);
}
};

const onMetrics = (m: DeckMetrics) => {
updateMetrics(m);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest creating an exported custom React hook that returns

  1. a state that contains the metrics
  2. a callback that updates the state, used as the onMetrics argument

I think it will be a more versatile and easier to use approach. I agree with @w1nklr that the ref shouldn't be necessary. I think it's at least worth a try.

@hkfb hkfb added the map-component Issues related to the map component. label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AspenTech Task owned by AspenTech enhancement New feature or request map-component Issues related to the map component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Component for displaying performance metrics

3 participants