raddbg_from_pdb: greatly improve speed of line info combining pass; do not linearly scan for line numbers, use line as hash -> slot key and search only slots

This commit is contained in:
Ryan Fleury
2024-02-09 15:31:24 -08:00
parent 44d9b57eb5
commit 6c872566af
2 changed files with 18 additions and 10 deletions
+16 -9
View File
@@ -2435,6 +2435,8 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
// gather line number map // gather line number map
CONS__SrcLineMapBucket *first_bucket = 0; CONS__SrcLineMapBucket *first_bucket = 0;
CONS__SrcLineMapBucket *last_bucket = 0; CONS__SrcLineMapBucket *last_bucket = 0;
U64 line_hash_slots_count = 1024;
CONS__SrcLineMapBucket **line_hash_slots = push_array(scratch.arena, CONS__SrcLineMapBucket *, line_hash_slots_count);
U64 line_count = 0; U64 line_count = 0;
U64 voff_count = 0; U64 voff_count = 0;
U64 max_line_num = 0; U64 max_line_num = 0;
@@ -2442,7 +2444,8 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
{ {
for (CONS__LineMapFragment *map_fragment = first; for (CONS__LineMapFragment *map_fragment = first;
map_fragment != 0; map_fragment != 0;
map_fragment = map_fragment->next){ map_fragment = map_fragment->next)
{
CONS_LineSequence *sequence = &map_fragment->sequence->line_seq; CONS_LineSequence *sequence = &map_fragment->sequence->line_seq;
U64 *seq_voffs = sequence->voffs; U64 *seq_voffs = sequence->voffs;
@@ -2451,6 +2454,7 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
for (U64 i = 0; i < seq_line_count; i += 1){ for (U64 i = 0; i < seq_line_count; i += 1){
U32 line_num = seq_line_nums[i]; U32 line_num = seq_line_nums[i];
U64 voff = seq_voffs[i]; U64 voff = seq_voffs[i];
U64 line_hash_slot_idx = line_num%line_hash_slots_count;
// update unique voff counter & max line number // update unique voff counter & max line number
voff_count += 1; voff_count += 1;
@@ -2458,19 +2462,22 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
// find match // find match
CONS__SrcLineMapBucket *match = 0; CONS__SrcLineMapBucket *match = 0;
for (CONS__SrcLineMapBucket *node = first_bucket; {
node != 0; for (CONS__SrcLineMapBucket *node = line_hash_slots[line_hash_slot_idx];
node = node->next){ node != 0;
if (node->line_num == line_num){ node = node->hash_next){
match = node; if (node->line_num == line_num){
break; match = node;
break;
}
} }
} }
// introduce new line if no match // introduce new line if no match
if (match == 0){ if (match == 0){
match = push_array(scratch.arena, CONS__SrcLineMapBucket, 1); match = push_array(scratch.arena, CONS__SrcLineMapBucket, 1);
SLLQueuePush(first_bucket, last_bucket, match); SLLQueuePush_N(first_bucket, last_bucket, match, order_next);
SLLStackPush_N(line_hash_slots[line_hash_slot_idx], match, hash_next);
match->line_num = line_num; match->line_num = line_num;
line_count += 1; line_count += 1;
} }
@@ -2493,7 +2500,7 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
CONS__SortKey *key_ptr = keys; CONS__SortKey *key_ptr = keys;
for (CONS__SrcLineMapBucket *node = first_bucket; for (CONS__SrcLineMapBucket *node = first_bucket;
node != 0; node != 0;
node = node->next, key_ptr += 1){ node = node->order_next, key_ptr += 1){
key_ptr->key = node->line_num; key_ptr->key = node->line_num;
key_ptr->val = node; key_ptr->val = node;
} }
+2 -1
View File
@@ -801,7 +801,8 @@ typedef struct CONS__SrcLineMapVoffBlock{
} CONS__SrcLineMapVoffBlock; } CONS__SrcLineMapVoffBlock;
typedef struct CONS__SrcLineMapBucket{ typedef struct CONS__SrcLineMapBucket{
struct CONS__SrcLineMapBucket *next; struct CONS__SrcLineMapBucket *order_next;
struct CONS__SrcLineMapBucket *hash_next;
U32 line_num; U32 line_num;
CONS__SrcLineMapVoffBlock *first_voff_block; CONS__SrcLineMapVoffBlock *first_voff_block;
CONS__SrcLineMapVoffBlock *last_voff_block; CONS__SrcLineMapVoffBlock *last_voff_block;