Skip to content

Conversation

@elliette
Copy link
Member

@elliette elliette commented Jul 30, 2025

Work towards #7917

Refactors generateFromCpuSamples to remove the intermediary JSON conversion step.

Before this PR:

generateFromCpuSamples went from vm_service.CpuSamples -> serialized to JSON -> deserialized to CpuProfileData:

  • generates a JSON representation of the stack frames (and as a side effect the timeline tree)
    • processes each node in the timeline tree, creates a JSON representation of the stack frame and assigns the frame ID to the node
    • keeps track of any frames missing package URIs
  • creates a JSON representation of the trace events
  • creates a JSON representation for the trace object, which includes the stack frames and trace events
  • does a bulk request for all the missing package URIs and updates the trace object with those URIs
  • deserializes the JSON trace object to a CpuProfileData object
    • As part of this, determines the median sample period
    • creates a CpuStackFrame object from the JSON stack frame representation

With this PR:

generateFromCpuSamples goes from vm_service.CpuSamples -> CpuProfileData

  • creates the profile metadata object
    • as part of this, determines the median sample period
  • generates the stack frames (and as a side effect the timeline tree)
    • processes each node in the timeline tree, creates a CpuStackFrame for it and assigns the frame ID to the node
    • keeps track of any frames missing package URIs, then at the end does a bulk request for all the missing package URIs and updates the frames with those URIs
  • converts the CPU samples to sample events
    • trace events are included in the sample events
  • finally, constructs the CpuProfileData object

Note: I filed #9353 to refactor this method more to avoid side-effects - the call to generate the stack frames creates the timeline tree and assigns frame IDs to every node in the tree. This was true before this change as well. However, I didn't want to change too much at once in this PR.

@elliette elliette marked this pull request as ready for review July 31, 2025 16:54
@elliette elliette requested review from a team, bkonyi and kenzieschmoll as code owners July 31, 2025 16:54
@elliette elliette requested review from jakemac53 and removed request for kenzieschmoll July 31, 2025 16:54
@elliette elliette changed the title [Draft] Remove intermediary JSON conversion from generateFromCpuSamples Remove intermediary JSON conversion from generateFromCpuSamples Jul 31, 2025
@elliette
Copy link
Member Author

elliette commented Aug 1, 2025

Note: Added a benchmark test to try to measure performance gains. Unfortunately seems pretty minimal, but I do think the code is cleaner without this step.

Benchmarks before this change:

29814.323529411766
31181.30769230769
29489.323529411766
32825.639344262294
37737.24528301887

Benchmarks after this change:

29160.1884057971
29295.420289855072
29321.144927536232
29251.405797101448
29419.176470588234

Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for fixing my questionable code 😉

@elliette elliette merged commit 9c4b332 into flutter:master Aug 7, 2025
41 checks passed
hrajwade96 pushed a commit to hrajwade96/devtools that referenced this pull request Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants