Skip to content

Profile: simplify Memory in heap snapshot#60930

Merged
topolarity merged 1 commit intoJuliaLang:masterfrom
topolarity:ct/fix-snapshot-size
Mar 6, 2026
Merged

Profile: simplify Memory in heap snapshot#60930
topolarity merged 1 commit intoJuliaLang:masterfrom
topolarity:ct/fix-snapshot-size

Conversation

@topolarity
Copy link
Copy Markdown
Member

@topolarity topolarity commented Feb 5, 2026

Memory somewhat awkwardly encodes the size of its data in an "internal" edge in the heap snapshot.

This is reasonable for String-owned Memory's, but it is pointlessly complex / confusing for GC-managed and inline-allocated Memory data arrays. This changes those bytes to be directly attributed to the Memory itself instead.

Also fix a bug that caused all Memory indices to be [0] in the heap snapshot.

Before:
image

After:
image

@topolarity topolarity added bugfix This change fixes an existing bug backport 1.10 Change should be backported to the 1.10 release backport 1.12 Change should be backported to release-1.12 backport 1.13 Change should be backported to release-1.13 labels Feb 5, 2026
@topolarity topolarity force-pushed the ct/fix-snapshot-size branch 2 times, most recently from 73efe43 to b177941 Compare February 5, 2026 14:14
@topolarity topolarity changed the title Profile: Fix sizeof Memory in heap snapshot Profile: fix sizeof Memory in heap snapshot Feb 5, 2026
@topolarity topolarity force-pushed the ct/fix-snapshot-size branch 2 times, most recently from 7d38e0e to 2d7d91f Compare February 5, 2026 14:19
@topolarity
Copy link
Copy Markdown
Member Author

I took a closer look and it turns out I was wrong about this bug.

This memory was being accounted for in the snapshot after all, but it was being put into secret "hidden" edges. This PR now moves those bytes from the "hidden" edge to the Memory object itself in the snapshot.

Re-requesting review given the major re-work.

@topolarity topolarity force-pushed the ct/fix-snapshot-size branch from ff33b90 to 9c94069 Compare February 5, 2026 15:15
@topolarity topolarity changed the title Profile: fix sizeof Memory in heap snapshot Profile: fix-up Memory in heap snapshot Feb 5, 2026
@topolarity topolarity changed the title Profile: fix-up Memory in heap snapshot Profile: fix Memory in heap snapshot Feb 5, 2026
@topolarity topolarity removed the backport 1.10 Change should be backported to the 1.10 release label Feb 5, 2026
@topolarity topolarity changed the title Profile: fix Memory in heap snapshot Profile: tweak Memory representation in heap snapshot Feb 5, 2026
@topolarity topolarity changed the title Profile: tweak Memory representation in heap snapshot Profile: simplify Memory in heap snapshot Feb 5, 2026
@topolarity topolarity changed the title Profile: simplify Memory in heap snapshot Profile: simplify Memory representation in heap snapshot Feb 5, 2026
@topolarity topolarity changed the title Profile: simplify Memory representation in heap snapshot Profile: simplify Memory in heap snapshot Feb 5, 2026
@vchuravy
Copy link
Copy Markdown
Member

vchuravy commented Feb 5, 2026

This memory was being accounted for in the snapshot after all, but it was being put into secret "hidden" edges. This PR now moves those bytes from the "hidden" edge to the Memory object itself in the snapshot.

If I recall correctly, I might have suggested this in case the memory buffer wrapped is aliased between multiple different objects.

@topolarity topolarity force-pushed the ct/fix-snapshot-size branch from 9c94069 to ca075d3 Compare February 5, 2026 15:28
Comment on lines +375 to +378
// Memory's that are string-owned or point to foreign memory have
// explicit snapshot edges to pointee data. Otherwise the array
// contents are treated as part of the Memory itself.
self_size += jl_genericmemory_nbytes(mem);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a nice simplficiation!

@topolarity topolarity force-pushed the ct/fix-snapshot-size branch from ca075d3 to 5b5c445 Compare February 5, 2026 15:30
This makes `Memory` more intuitive to interpret in heap snapshots.
@JeffBezanson
Copy link
Copy Markdown
Member

Why do the indices in the screenshot appear to be random numbers?

@topolarity
Copy link
Copy Markdown
Member Author

Why do the indices in the screenshot appear to be random numbers?

It's being sorted and it's a very large array, so those are the largest elements

@JeffBezanson
Copy link
Copy Markdown
Member

Ah, of course.

This was referenced Feb 25, 2026
@topolarity topolarity merged commit 7f14dc3 into JuliaLang:master Mar 6, 2026
9 checks passed
KristofferC pushed a commit that referenced this pull request Mar 12, 2026
`Memory` somewhat awkwardly encodes the size of its data in an
"internal" edge in the heap snapshot.

This is reasonable for String-owned Memory's, but it is pointlessly
complex / confusing for GC-managed and inline-allocated Memory data
arrays. This changes those bytes to be directly attributed to the
`Memory` itself instead.

Also fix a bug that caused all Memory indices to be `[0]` in the heap
snapshot.

(cherry picked from commit 7f14dc3)
@KristofferC KristofferC removed the backport 1.13 Change should be backported to release-1.13 label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.12 Change should be backported to release-1.12 bugfix This change fixes an existing bug profiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants