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

add trimming of new usings_backedges and scanned_methods fields #57879

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,14 @@ static void jl_queue_module_for_serialization(jl_serializer_state *s, jl_module_
jl_queue_for_serialization(s, module_usings_getmod(m, i));
}

jl_queue_for_serialization(s, m->usings_backedges);
jl_queue_for_serialization(s, m->scanned_methods);
if (jl_options.trim || jl_options.strip_ir) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this should be tied to strip-ir or trim, but either seems ok?

record_field_change((jl_value_t**)&m->usings_backedges, jl_nothing);
record_field_change((jl_value_t**)&m->scanned_methods, jl_nothing);
}
else {
jl_queue_for_serialization(s, m->usings_backedges);
jl_queue_for_serialization(s, m->scanned_methods);
}
}

// Anything that requires uniquing or fixing during deserialization needs to be "toplevel"
Expand Down Expand Up @@ -1322,10 +1328,10 @@ static void jl_write_module(jl_serializer_state *s, uintptr_t item, jl_module_t
newm->line = 0;
newm->usings_backedges = NULL;
arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_module_t, usings_backedges)));
arraylist_push(&s->relocs_list, (void*)backref_id(s, m->usings_backedges, s->link_ids_relocs));
arraylist_push(&s->relocs_list, (void*)backref_id(s, get_replaceable_field(&m->usings_backedges, 1), s->link_ids_relocs));
newm->scanned_methods = NULL;
arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_module_t, scanned_methods)));
arraylist_push(&s->relocs_list, (void*)backref_id(s, m->scanned_methods, s->link_ids_relocs));
arraylist_push(&s->relocs_list, (void*)backref_id(s, get_replaceable_field(&m->scanned_methods, 1), s->link_ids_relocs));

// After reload, everything that has happened in this process happened semantically at
// (for .incremental) or before jl_require_world, so reset this flag.
Expand Down Expand Up @@ -3630,7 +3636,7 @@ static int jl_validate_binding_partition(jl_binding_t *b, jl_binding_partition_t
jl_sym_t *name = b->globalref->name;
JL_LOCK(&mod->lock);
jl_atomic_store_release(&mod->export_set_changed_since_require_world, 1);
if (mod->usings_backedges) {
if (mod->usings_backedges != jl_nothing) {
for (size_t i = 0; i < jl_array_len(mod->usings_backedges); i++) {
jl_module_t *edge = (jl_module_t*)jl_array_ptr_ref(mod->usings_backedges, i);
jl_binding_t *importee = jl_get_module_binding(edge, name, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/trimming/trimming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let exe_suffix = splitext(Base.julia_exename())[2]

hello_exe = joinpath(@__DIR__, "hello" * exe_suffix)
@test readchomp(`$hello_exe`) == "Hello, world!"
@test filesize(hello_exe) < filesize(unsafe_string(Base.JLOptions().image_file))/10
@test filesize(hello_exe) < 2000000
Copy link
Member Author

Choose a reason for hiding this comment

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

For me the size is now 1633392. Not sure if this holds on all platforms but we'll find out.

Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure we only test trimming on Linux x86-64, but I'm very happy to have this test tightened anyway


basic_jll_exe = joinpath(@__DIR__, "basic_jll" * exe_suffix)
lines = split(readchomp(`$basic_jll_exe`), "\n")
Expand Down