perfCounter min value not working as expected

Hi,

when using the perfCounter class to track several values and get their min, max, etc. I’ve found that the min value always returns 0 if the values you add are >0. This seems to be caused by the internal _min value being set to 0 in the constructor. All following checks use Math.min to compare the current value to _min and will therefore always return 0 if they are positive.

Maybe it should be initialized with Number.MAX_VALUE. The same thing probably happens when adding negative values to the perfCounter and getting the max value, which is also set to 0 in the constructor and could be initialized with Number.MIN_VALUE. Although this case does not seem that important when all performance metrics are positive.

Here is a playground demonstrating the issue with the min value (Babylon.js 9.17.1).

Thanks.

Thanks for the report and playground!

You’re right, this is a bug.

_min and _max start at 0 , so positive-only samples leave min at 0 , while negative-only samples leave max at 0 .

fetchNewFrame() does not record zero as a sample.

Thanks for catching this!

I’ll do a PR asap!

Fix PerfCounter min/max initialization by deltakosh · Pull Request #18721 · BabylonJS/Babylon.js