Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve all ancestors of nodes that weren't filtered out #2

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

JianFangAtRai
Copy link
Contributor

This PR is to fix the issue Preserve all ancestors of nodes that weren't filtered out(#1). The changes are as follows.

  1. removed the logic to remove all ancestors if a node is marked
  2. removed the children of a node instead to prevent them from becoming dangling nodes
  3. fixed tests

Tested with 11GB of RAI engine heap snapshot and the ancestors were indeed shown up in the containment view in chrome Dev tools.

@JianFangAtRai JianFangAtRai requested a review from Drvi January 26, 2024 16:40
@JianFangAtRai JianFangAtRai self-assigned this Jan 26, 2024
@Drvi
Copy link
Member

Drvi commented Jan 29, 2024

Locally, with both master and this PR, when I subsample a snapshot from a fresh Julia session, I can still see results that are not quite right -- even with a relatively fresh Julia session, I can see a lot of <pooled> elements that don't point to anything (but I'd expect them to point to an array) and I can't see any such <pooled> elements in the original snapshot. I think we're not getting it quite right

Also, from a performance and memory pressure perspective, we don't need to create the children_edges dictionary of arrays, which usually allocates many times per node -- instead, we can utilize the fact that each node has its children already laid out in the edges array in order. If we make a cumulative sum of edge count for each node, we can then easily access the edges directly, a la:

# cumsum_edges = cumsum(nodes.edge_count)
function _mark!(seen, queue, node_idx, nodes, cumsum_edges)
    get!(seen, node_idx) do
        cumcnt = cumsum_edges[node_idx]
        prev_cumcnt = get(cumsum_edges, node_idx-1, 0)

        for child_node_idx in @view(nodes.edges.to_pos[prev_cumcnt+1:cumcnt])
            get!(seen, child_node_idx) do
                push!(queue, child_node_idx)
            end
        end
        return nothing
    end
end

@JianFangAtRai
Copy link
Contributor Author

Locally, with both master and this PR, when I subsample a snapshot from a fresh Julia session, I can still see results that are not quite right -- even with a relatively fresh Julia session, I can see a lot of <pooled> elements that don't point to anything (but I'd expect them to point to an array) and I can't see any such <pooled> elements in the original snapshot. I think we're not getting it quite right

Also, from a performance and memory pressure perspective, we don't need to create the children_edges dictionary of arrays, which usually allocates many times per node -- instead, we can utilize the fact that each node has its children already laid out in the edges array in order. If we make a cumulative sum of edge count for each node, we can then easily access the edges directly, a la:

# cumsum_edges = cumsum(nodes.edge_count)
function _mark!(seen, queue, node_idx, nodes, cumsum_edges)
    get!(seen, node_idx) do
        cumcnt = cumsum_edges[node_idx]
        prev_cumcnt = get(cumsum_edges, node_idx-1, 0)

        for child_node_idx in @view(nodes.edges.to_pos[prev_cumcnt+1:cumcnt])
            get!(seen, child_node_idx) do
                push!(queue, child_node_idx)
            end
        end
        return nothing
    end
end

Will look into it. Thanks

@Drvi
Copy link
Member

Drvi commented Jan 29, 2024

Actually, maybe the thing with <pooled> not pointing to any array is expected, what we don't want is a deleted <pooled> that was pointing to an Array that is now not reachable... right?

@JianFangAtRai
Copy link
Contributor Author

Actually, maybe the thing with <pooled> not pointing to any array is expected, what we don't want is a deleted <pooled> that was pointing to an Array that is now not reachable... right?

correct

Copy link
Member

@Drvi Drvi left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great! I think it would be great to also add a test that each retained node can be traced to a root, then let's merge!

@JianFangAtRai
Copy link
Contributor Author

I am going to merge it as it is for now. There are other issues that I found during testing and debugging. I will send out another PR to address them soon.

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