From b76fc585431e7d10338bb175334945294b4a57ac Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 22 May 2023 15:23:24 +0100 Subject: Inline `are_types_identical_unique_tuples` to improve `odin_doc_type` performance --- src/docs_writer.cpp | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 7488e955a..3c27552f5 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -471,6 +471,8 @@ gb_internal OdinDocArray odin_doc_add_entity_as_slice(OdinDo return odin_write_item_as_slice(w, index); } + + gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { if (type == nullptr) { return 0; @@ -481,12 +483,41 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { } for (auto const &entry : w->type_cache) { // NOTE(bill): THIS IS SLOW - Type *other = entry.key; - if (are_types_identical_unique_tuples(type, other)) { - OdinDocTypeIndex index = entry.value; - map_set(&w->type_cache, type, index); - return index; + Type *x = type; + Type *y = entry.key; + + if (x == y) { + goto do_set; + } + + if (!x | !y) { + continue; + } + + if (x->kind == Type_Named) { + Entity *e = x->Named.type_name; + if (e->TypeName.is_type_alias) { + x = x->Named.base; + } } + if (y->kind == Type_Named) { + Entity *e = y->Named.type_name; + if (e->TypeName.is_type_alias) { + y = y->Named.base; + } + } + if (x->kind != y->kind) { + continue; + } + + if (!are_types_identical_internal(x, y, true)) { + continue; + } + + do_set: + OdinDocTypeIndex index = entry.value; + map_set(&w->type_cache, type, index); + return index; } -- cgit v1.2.3 From 248f14a1efe95294fe20b4f930be4a948396ff44 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 22 May 2023 15:29:01 +0100 Subject: Correct entity flag generation --- src/docs_writer.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 3c27552f5..1e34faa8b 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -887,13 +887,12 @@ gb_internal OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) break; } - if (e->flags & EntityFlag_Param) { - if (e->flags & EntityFlag_Using) { flags |= OdinDocEntityFlag_Param_Using; } - if (e->flags & EntityFlag_ConstInput) { flags |= OdinDocEntityFlag_Param_Const; } - if (e->flags & EntityFlag_Ellipsis) { flags |= OdinDocEntityFlag_Param_Ellipsis; } - if (e->flags & EntityFlag_NoAlias) { flags |= OdinDocEntityFlag_Param_NoAlias; } - if (e->flags & EntityFlag_AnyInt) { flags |= OdinDocEntityFlag_Param_AnyInt; } - } + if (e->flags & EntityFlag_Using) { flags |= OdinDocEntityFlag_Param_Using; } + if (e->flags & EntityFlag_ConstInput) { flags |= OdinDocEntityFlag_Param_Const; } + if (e->flags & EntityFlag_Ellipsis) { flags |= OdinDocEntityFlag_Param_Ellipsis; } + if (e->flags & EntityFlag_NoAlias) { flags |= OdinDocEntityFlag_Param_NoAlias; } + if (e->flags & EntityFlag_AnyInt) { flags |= OdinDocEntityFlag_Param_AnyInt; } + if (e->scope && (e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) && !is_entity_exported(e)) { flags |= OdinDocEntityFlag_Private; } -- cgit v1.2.3 From 38b64dc5dfeb141cb7e9cca790f897e762374ead Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 22 May 2023 20:48:13 +0100 Subject: Improve doc_writer.cpp performance --- src/docs_writer.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 1e34faa8b..7dab5a8b1 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -30,6 +30,7 @@ struct OdinDocWriter { PtrMap pkg_cache; PtrMap entity_cache; PtrMap type_cache; + PtrMap stable_type_cache; OdinDocWriterItemTracker files; OdinDocWriterItemTracker pkgs; @@ -59,6 +60,7 @@ gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) { map_init(&w->pkg_cache); map_init(&w->entity_cache); map_init(&w->type_cache); + map_init(&w->stable_type_cache); odin_doc_writer_item_tracker_init(&w->files, 1); odin_doc_writer_item_tracker_init(&w->pkgs, 1); @@ -77,6 +79,7 @@ gb_internal void odin_doc_writer_destroy(OdinDocWriter *w) { map_destroy(&w->pkg_cache); map_destroy(&w->entity_cache); map_destroy(&w->type_cache); + map_destroy(&w->stable_type_cache); } @@ -477,6 +480,12 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { if (type == nullptr) { return 0; } + + Type **mapped_type = map_get(&w->stable_type_cache, type); // may map to itself + if (mapped_type && *mapped_type) { + type = *mapped_type; + } + OdinDocTypeIndex *found = map_get(&w->type_cache, type); if (found) { return *found; @@ -517,6 +526,7 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { do_set: OdinDocTypeIndex index = entry.value; map_set(&w->type_cache, type, index); + map_set(&w->stable_type_cache, type, entry.key); return index; } @@ -526,6 +536,7 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { OdinDocTypeIndex type_index = 0; type_index = odin_doc_write_item(w, &w->types, &doc_type, &dst); map_set(&w->type_cache, type, type_index); + map_set(&w->stable_type_cache, type, type); switch (type->kind) { case Type_Basic: -- cgit v1.2.3 From bdbbaf6c880c1ac481859160cb632b49ecbe6b46 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 22 May 2023 21:34:20 +0100 Subject: Disable stable_type_cache for the time being --- src/docs_writer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 7dab5a8b1..18178dd51 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -481,10 +481,10 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { return 0; } - Type **mapped_type = map_get(&w->stable_type_cache, type); // may map to itself - if (mapped_type && *mapped_type) { - type = *mapped_type; - } + // Type **mapped_type = map_get(&w->stable_type_cache, type); // may map to itself + // if (mapped_type && *mapped_type) { + // type = *mapped_type; + // } OdinDocTypeIndex *found = map_get(&w->type_cache, type); if (found) { -- cgit v1.2.3 From 3a61350f4b362ae9d3cd03940588f83b035ba33d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 22 May 2023 21:48:32 +0100 Subject: Add debug messages to docs_writer.cpp --- src/docs_writer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 18178dd51..2dd2f338b 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -52,6 +52,7 @@ gb_internal void odin_doc_writer_item_tracker_init(OdinDocWriterItemTracker * gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) { + debugf("odin_doc_writer_prepare\n"); w->state = OdinDocWriterState_Preparing; string_map_init(&w->string_cache); @@ -72,6 +73,7 @@ gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) { gb_internal void odin_doc_writer_destroy(OdinDocWriter *w) { + debugf("odin_doc_writer_destroy\n"); gb_free(heap_allocator(), w->data); string_map_destroy(&w->string_cache); @@ -105,6 +107,7 @@ gb_internal isize odin_doc_writer_calc_total_size(OdinDocWriter *w) { } gb_internal void odin_doc_writer_start_writing(OdinDocWriter *w) { + debugf("odin_doc_writer_start_writing\n"); w->state = OdinDocWriterState_Writing; string_map_clear(&w->string_cache); @@ -141,6 +144,7 @@ gb_internal void odin_doc_writer_assign_tracker(OdinDocArray *array, OdinDocW gb_internal void odin_doc_writer_end_writing(OdinDocWriter *w) { + debugf("odin_doc_writer_end_writing\n"); OdinDocHeader *h = w->header; gb_memmove(h->base.magic, OdinDocHeader_MagicString, gb_strlen(OdinDocHeader_MagicString)); @@ -951,6 +955,8 @@ gb_internal OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) } gb_internal void odin_doc_update_entities(OdinDocWriter *w) { + debugf("odin_doc_update_entities %s\n", w->state ? "preparing" : "writing"); + { // NOTE(bill): Double pass, just in case entities are created on odin_doc_type auto entities = array_make(heap_allocator(), 0, w->entity_cache.count); @@ -1015,6 +1021,8 @@ gb_internal OdinDocArray odin_doc_add_pkg_entries(OdinDocWrit return {}; } + debugf("odin_doc_add_pkg_entries %s -> package %.*s\n", w->state ? "preparing" : "writing", LIT(pkg->name)); + auto entries = array_make(heap_allocator(), 0, w->entity_cache.count); defer (array_free(&entries)); @@ -1058,6 +1066,8 @@ gb_internal OdinDocArray odin_doc_add_pkg_entries(OdinDocWrit gb_internal void odin_doc_write_docs(OdinDocWriter *w) { + debugf("odin_doc_write_docs %s", w->state ? "preparing" : "writing"); + auto pkgs = array_make(heap_allocator(), 0, w->info->packages.count); defer (array_free(&pkgs)); for (auto const &entry : w->info->packages) { @@ -1073,6 +1083,7 @@ gb_internal void odin_doc_write_docs(OdinDocWriter *w) { } } + debugf("odin_doc_update_entities sort pkgs %s\n", w->state ? "preparing" : "writing"); gb_sort_array(pkgs.data, pkgs.count, cmp_ast_package_by_name); for_array(i, pkgs) { @@ -1133,6 +1144,7 @@ gb_internal void odin_doc_write_docs(OdinDocWriter *w) { gb_internal void odin_doc_write_to_file(OdinDocWriter *w, char const *filename) { + debugf("odin_doc_write_to_file %s\n", filename); gbFile f = {}; gbFileError err = gb_file_open_mode(&f, gbFileMode_Write, filename); if (err != gbFileError_None) { @@ -1143,6 +1155,7 @@ gb_internal void odin_doc_write_to_file(OdinDocWriter *w, char const *filename) defer (gb_file_close(&f)); if (gb_file_write(&f, w->data, w->data_len)) { err = gb_file_truncate(&f, w->data_len); + debugf("Wrote .odin-doc file to: %s\n", filename); gb_printf("Wrote .odin-doc file to: %s\n", filename); } } @@ -1153,6 +1166,8 @@ gb_internal void odin_doc_write(CheckerInfo *info, char const *filename) { defer (odin_doc_writer_destroy(w)); w->info = info; + debugf("odin_doc_write %s\n", filename); + odin_doc_writer_prepare(w); odin_doc_write_docs(w); -- cgit v1.2.3