Skip to content

Commit dba4abb

Browse files
vtjnashLebedevRI
authored andcommitted
staticdata: stop compressing and storing large IR (JuliaLang#58172)
Compressing IR adds Methods roots, which tend to become quite expensive to store after some time. We also used to store the inferred code, but since we never actually look at that again now (since now the compiler avoids using --output-ji or --sysimage-native-code=no or --pkgimages=no) it is now quite a bit of wasted space also. Roughly 40 MB saved on disk (165 MB -> 124 MB) if I measured correctly: ``` usr/lib/julia/sys.so : section size addr .note.gnu.build-id 36 680 .gnu.hash 52 720 .dynsym 2760 776 .dynstr 2070 3536 .gnu.version 230 5606 .gnu.version_r 160 5840 .rela.dyn 943440 6000 .rela.plt 2256 949440 .init 27 954368 .plt 1520 954400 .plt.got 8 955920 .text 17207656 955936 .fini 13 18163592 .rodata 18388 18165760 .eh_frame_hdr 315940 18184148 .eh_frame 1525972 18500088 .init_array 8 20032896 .fini_array 8 20032904 .dynamic 496 20032912 .got 128 20033408 .got.plt 776 20033536 .data 8 20034312 .bss 8 20034320 .lbss 80336 20034336 .lrodata 303064 20118768 .ldata 123852168 20425928 .comment 43 0 .debug_info 10028208 0 .debug_abbrev 18197 0 .debug_line 6581659 0 .debug_str 578898 0 .debug_ranges 10854832 0 .debug_gnu_pubnames 3065385 0 .debug_gnu_pubtypes 352332 0 Total 175737082 ```
1 parent a7aa573 commit dba4abb

File tree

4 files changed

+14
-47
lines changed

4 files changed

+14
-47
lines changed

src/aotcompile.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -675,20 +675,6 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
675675
fargs[0] = (jl_value_t*)codeinfos;
676676
void *data = jl_emit_native(codeinfos, llvmmod, &cgparams, external_linkage);
677677

678-
// examine everything just emitted and save it to the caches
679-
if (!external_linkage) {
680-
for (size_t i = 0, l = jl_array_nrows(codeinfos); i < l; i++) {
681-
jl_value_t *item = jl_array_ptr_ref(codeinfos, i);
682-
if (jl_is_code_instance(item)) {
683-
// now add it to our compilation results
684-
jl_code_instance_t *codeinst = (jl_code_instance_t*)item;
685-
jl_code_info_t *src = (jl_code_info_t*)jl_array_ptr_ref(codeinfos, ++i);
686-
assert(jl_is_code_info(src));
687-
jl_add_codeinst_to_cache(codeinst, src);
688-
}
689-
}
690-
}
691-
692678
// move everything inside, now that we've merged everything
693679
// (before adding the exported headers)
694680
((jl_native_code_desc_t*)data)->M.withModuleDo([&](Module &M) {

src/gf.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,30 +2846,10 @@ void jl_read_codeinst_invoke(jl_code_instance_t *ci, uint8_t *specsigflags, jl_c
28462846

28472847
jl_method_instance_t *jl_normalize_to_compilable_mi(jl_method_instance_t *mi JL_PROPAGATES_ROOT);
28482848

2849-
JL_DLLEXPORT void jl_add_codeinst_to_cache(jl_code_instance_t *codeinst, jl_code_info_t *src)
2850-
{
2851-
assert(jl_is_code_info(src));
2852-
jl_method_instance_t *mi = jl_get_ci_mi(codeinst);
2853-
if (jl_generating_output() && jl_is_method(mi->def.method) && jl_atomic_load_relaxed(&codeinst->inferred) == jl_nothing) {
2854-
jl_value_t *compressed = jl_compress_ir(mi->def.method, src);
2855-
// These should already be compatible (and should be an assert), but make sure of it anyways
2856-
if (jl_is_svec(src->edges)) {
2857-
jl_atomic_store_release(&codeinst->edges, (jl_svec_t*)src->edges);
2858-
jl_gc_wb(codeinst, src->edges);
2859-
}
2860-
jl_atomic_store_release(&codeinst->debuginfo, src->debuginfo);
2861-
jl_gc_wb(codeinst, src->debuginfo);
2862-
jl_atomic_store_release(&codeinst->inferred, compressed);
2863-
jl_gc_wb(codeinst, compressed);
2864-
}
2865-
}
2866-
2867-
28682849
JL_DLLEXPORT void jl_add_codeinst_to_jit(jl_code_instance_t *codeinst, jl_code_info_t *src)
28692850
{
28702851
assert(jl_is_code_info(src));
28712852
jl_emit_codeinst_to_jit(codeinst, src);
2872-
jl_add_codeinst_to_cache(codeinst, src);
28732853
}
28742854

28752855
jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t world)

src/julia_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ JL_DLLEXPORT jl_method_instance_t *jl_get_unspecialized(jl_method_t *def JL_PROP
688688
JL_DLLEXPORT void jl_read_codeinst_invoke(jl_code_instance_t *ci, uint8_t *specsigflags, jl_callptr_t *invoke, void **specptr, int waitcompile);
689689
JL_DLLEXPORT jl_method_instance_t *jl_method_match_to_mi(jl_method_match_t *match, size_t world, size_t min_valid, size_t max_valid, int mt_cache);
690690
JL_DLLEXPORT void jl_add_codeinst_to_jit(jl_code_instance_t *codeinst, jl_code_info_t *src);
691-
JL_DLLEXPORT void jl_add_codeinst_to_cache(jl_code_instance_t *codeinst, jl_code_info_t *src);
692691

693692
JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst_uninit(jl_method_instance_t *mi, jl_value_t *owner);
694693
JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(

src/staticdata.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -954,24 +954,26 @@ static void jl_insert_into_serialization_queue(jl_serializer_state *s, jl_value_
954954
assert(!jl_object_in_image((jl_value_t*)tn->wrapper));
955955
}
956956
}
957-
if (s->incremental && jl_is_code_instance(v)) {
957+
if (jl_is_code_instance(v)) {
958958
jl_code_instance_t *ci = (jl_code_instance_t*)v;
959959
jl_method_instance_t *mi = jl_get_ci_mi(ci);
960-
// make sure we don't serialize other reachable cache entries of foreign methods
961-
// Should this now be:
962-
// if (ci !in ci->defs->cache)
963-
// record_field_change((jl_value_t**)&ci->next, NULL);
964-
// Why are we checking that the method/module this originates from is in_image?
965-
// and then disconnect this CI?
966-
if (jl_object_in_image((jl_value_t*)mi->def.value)) {
967-
// TODO: if (ci in ci->defs->cache)
968-
record_field_change((jl_value_t**)&ci->next, NULL);
960+
if (s->incremental) {
961+
// make sure we don't serialize other reachable cache entries of foreign methods
962+
// Should this now be:
963+
// if (ci !in ci->defs->cache)
964+
// record_field_change((jl_value_t**)&ci->next, NULL);
965+
// Why are we checking that the method/module this originates from is in_image?
966+
// and then disconnect this CI?
967+
if (jl_object_in_image((jl_value_t*)mi->def.value)) {
968+
// TODO: if (ci in ci->defs->cache)
969+
record_field_change((jl_value_t**)&ci->next, NULL);
970+
}
969971
}
970972
jl_value_t *inferred = jl_atomic_load_relaxed(&ci->inferred);
971973
if (inferred && inferred != jl_nothing) { // disregard if there is nothing here to delete (e.g. builtins, unspecialized)
972974
jl_method_t *def = mi->def.method;
973975
if (jl_is_method(def)) { // don't delete toplevel code
974-
int is_relocatable = jl_is_code_info(inferred) ||
976+
int is_relocatable = !s->incremental || jl_is_code_info(inferred) ||
975977
(jl_is_string(inferred) && jl_string_len(inferred) > 0 && jl_string_data(inferred)[jl_string_len(inferred) - 1]);
976978
if (!is_relocatable) {
977979
inferred = jl_nothing;
@@ -993,7 +995,7 @@ static void jl_insert_into_serialization_queue(jl_serializer_state *s, jl_value_
993995
if (inferred == jl_nothing) {
994996
record_field_change((jl_value_t**)&ci->inferred, jl_nothing);
995997
}
996-
else if (jl_is_string(inferred)) {
998+
else if (s->incremental && jl_is_string(inferred)) {
997999
// New roots for external methods
9981000
if (jl_object_in_image((jl_value_t*)def)) {
9991001
void **pfound = ptrhash_bp(&s->method_roots_index, def);

0 commit comments

Comments
 (0)