Skip to content

Convert some code to use the non-inverted call node table even while we're showing the inverted call tree#4899

Merged
mstange merged 8 commits into
firefox-devtools:mainfrom
mstange:fast-invert-preparation
Jan 25, 2024
Merged

Convert some code to use the non-inverted call node table even while we're showing the inverted call tree#4899
mstange merged 8 commits into
firefox-devtools:mainfrom
mstange:fast-invert-preparation

Conversation

@mstange

@mstange mstange commented Jan 23, 2024

Copy link
Copy Markdown
Contributor

To make inverting the call tree fast, we need to stop computing the entire inverted call node table upfront. However, we have many places in the code which work on the call node table directly.
Luckily, many of these places can be changed to use the non-inverted call node table instead. There are three types of code which can be changed like this:

  • Code which already only runs in a non-inverted context: flame graph + stack chart, and specialized computeXYZNonInverted functions
  • Code which just wants to know the depth of the stack for a certain sample: ThreadStackGraph and maxDepth
  • Code which wants to know the call path for a sample: the code that computes the new selected + expanded call path when clicking the activity graph

The non-inverted call node table is completely sufficient for computing the call path of a sample.

This PR converts the places listed above to use the non-inverted call node table.

An unfortunate aspect of this PR is the fact that the IndexIntoCallNodeTable type now becomes quite ambiguous. It can be an index into the inverted or into the non-inverted call node table, often depending on context. This is going to be confusing for readers of the code, and if you use the index in the wrong table there's nothing that catches that mistake.
I haven't found a solution to this problem yet. For now I think we should accept the ambiguity, get to the end of the fast-invert work, and then think of a solution that makes sense once that's all done.

@mstange mstange requested a review from julienw January 23, 2024 16:37
@mstange mstange self-assigned this Jan 23, 2024
@mstange mstange changed the title More preparations for a fast inverted tree Convert some code to use the non-inverted call node table even while we're showing the inverted call tree Jan 23, 2024
@codecov

codecov Bot commented Jan 23, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (3fd468f) 88.42% compared to head (846c195) 88.43%.

❗ Current head 846c195 differs from pull request most recent head 806dd22. Consider uploading reports for the commit 806dd22 to get more accurate results

Files Patch % Lines
src/components/flame-graph/FlameGraph.js 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4899      +/-   ##
==========================================
+ Coverage   88.42%   88.43%   +0.01%     
==========================================
  Files         304      304              
  Lines       27186    27189       +3     
  Branches     7331     7328       -3     
==========================================
+ Hits        24039    24045       +6     
+ Misses       2929     2926       -3     
  Partials      218      218              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julienw julienw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this seems to work perfectly and I understood it all 😆

Comment on lines +67 to 71
for (let i = 0; i < nonInvertedCallNodeTable.depth.length; i++) {
if (nonInvertedCallNodeTable.depth[i] > maxDepth) {
maxDepth = nonInvertedCallNodeTable.depth[i];
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes me think there's a maxDepth property in the call node table, could we use it directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(not especially in this PR though)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh I forgot about that property, but you're right!

threadsKey,
callNodePath.slice(0, 1), // Select a root node
{ source: 'auto' },
callNodePath // Expand the full path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, this makes me think we might want to do that as well when switching from non-inverted to inverted.
(looking at the code, it looks like we're trying to do it but it's buggy)

Flame graph code is always executed with a non-inverted CallNodeInfo, so
getNonInvertedCallNodeTable always returns the same as getCallNodeTable.

The purpose of this patch is to remove more callers of getCallNodeTable()
without changing behavior.
…guaranteed to have a non-inverted call node info.

In these three functions we've already checked whether the CallNodeInfo
is inverted. We only get here if it's the non-inverted CallNodeInfo.
So getStackIndexToNonInvertedCallNodeIndex will return the same as
getStackIndexToCallNodeIndex.
This replaces selectLeafCallNode and selectRootCallNode with a new
action creater called selectSelfCallNode which handles both the
inverted and the non-inverted case.
@mstange mstange force-pushed the fast-invert-preparation branch from 846c195 to 806dd22 Compare January 25, 2024 19:27
@mstange mstange merged commit c1b4d06 into firefox-devtools:main Jan 25, 2024
@julienw julienw mentioned this pull request Feb 6, 2024
julienw added a commit that referenced this pull request Feb 6, 2024
[@canova Nazım Can Altınova] Return null instead of throwing an error if it fails to get the resource name in active tab view (#4905)
[@fqueze Florian Quèze] Improve the precision of the getFittedText implementation. (#4893)
[@fqueze Florian Quèze] Show marker count next to the marker name in the marker chart when a marker is hovered. (#4892)
[@mstange Markus Stange] Convert some code to use the non-inverted call node table even while we're showing the inverted call tree (Merge PR #4899)
[@canova Nazım Can Altınova] Bring the max stacking depth limit back for marker timings (#4898)
[@mstange Markus Stange] Various preparations in call tree code for fast inverted tree (Merge PR #4897)
[@mstange Markus Stange] Move call node path/index conversion functions into CallNodeInfo (Merge PR #4896)
[@mstange Markus Stange] Make mergeFunction fast (Merge PR #4895)
[@gthb Gunnlaugur Thor Briem] feat: support from-url profiles in compare (#4875)

And all the locale contributors:
de: Michael Köhler
el: Jim Spentzos
en-GB: Ian Neal
es-CL: ravmn
fr: Théo Chevalier
fy-NL: Fjoerfoks
ia: Melo46
it: Francesco Lodolo [:flod]
nl: Fjoerfoks, Mark Heijl
pt-BR: Marcelo Ghelman
ru: Valery Ledovskoy
sv-SE: Andreas Pettersson
uk: Artem Polivanchuk
zh-CN: 你我皆凡人, Olvcpr423, Pontoon
zh-TW: Pin-guang Chen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants