sturdykeep / backbone

Strong & flexible game library for Flutter, that drinks milk šŸ„›
Other
37 stars 1 forks source link

Sample-based performance measuring with `prefmon` #77

Closed skyne98 closed 1 year ago

skyne98 commented 1 year ago

Switch from time calculation and aggregation to sampling in prefmon. This means moving from calculating time spent in a function or block of code and reporting it to reporting a place in code where execution currently happens whenever the external monitoring tool requires it. It should resolve the issue of too much overhead from aggregating data and allow for nearly infinite (and configurable) granularity in measurements.

Source of inspiration: .NET, JS and Dart debugging tools.

Acceptance criteria:

  1. There is an isolate (or any other agent running in parallel to the program) that keeps track of the current block of code in execution, based on the program itself reporting it (without some specific rate, real-time)
  2. prefmon, having a TCP (WS) connection to it, requests or receives a current executing scope at a specified rate
  3. Over a specific timeframe, prefmon should receive a specific number of samples (for example 1 000 000 over 1000 ms or 1000 per 1 ms) so that it can make an educated guess about the % of time that was spent in a specific part of code
  4. Either come up with an automatic way of reporting the current place of execution, or make a performanceEnter(<function or block name>) and performanceLeave() functions that directly report to the isolate with as little overhead as possible
  5. Performance measuring functions get stripped in release mode, so that they don't influence performance
  6. Old performance measuring code goes away completely

Some notes: On the isolate side, the current place of execution is probably not a single name, but a stack, which represents the current call stack. Otherwise, the performanceLeave() will have nothing to reset and "prefmon" will not be able to decide in which exact "child" function it is.

Dev-Owl commented 1 year ago

Would this not spoil the code with hunderts of enter/leave codes? It looks like a more complicated way to archive the same. Only advantage is that it goes to an isolate.

For me it should be KISS:

I would vote for a dead simple function to wrap any call, it would report start and end. If performance testing is off it just calls the function. If the performance flag is const the compiler should kickoff the not needed code.

This would allow the user to call any function with thus to monitor it.

Dev-Owl commented 1 year ago

In addition to the above, I would currently vote for using: Pub.dev as it provides a solution for all target platforms.