Skip to content

Conversation

minseoc03
Copy link

@minseoc03 minseoc03 commented May 14, 2025

Resolves #2

Summary

This PR refactors the core date structures in llvm-block to improve performance and memory usage.

  • Replace the std::vector<collist*> table with TableMap = std::unordered_map<int, collist*> (keyed by line number).
  • Replace the std::list<col*>cols inside collist with `std::unordered_map<int, col*> (keyed by column number)
  • Update all lookup sites (CreateTable, InsertTable, CompareLR) to use fast map.find() instead of linear scans or repeated resize().

Motivation

  • Sparse line numbers are common after optimization or macro expansion; the old vector approach wasted memory and spent time resizing.
  • std::list lookups in searchcol() were O(n) in the number of columns; switching to unordered_map yields amortized O(1) lookups.

What's Changed

llvm-block.cpp

  • Swapped std::vector<collist*> table for using TableMap = std::unordered_map<int, collist*>
  • Replaced every table.at(line) + resize() pattern with table.find(line) + insert-if-missing.
  • Updated CreateTable(), InsertTable(), and CompareLR() to use the new map.

table.h/table.cpp

  • Changed collist::cols from std::list<col*> to std::unordered_map<int, col*>
  • Rewrote push(col*) and searchcol(int) to use cols.find() for O(1) insert / lookup.

@eomiso eomiso self-requested a review May 16, 2025 07:11
@eomiso eomiso self-assigned this May 16, 2025
@eomiso eomiso changed the title feat: replace vector into map refac: replace vector into map May 16, 2025
@eomiso
Copy link
Contributor

eomiso commented May 20, 2025

Hi @minseoc03,
The code review for this PR is taking a bit longer than usual due to some other priorities currently in progress.
I'm planning to merge this after I complete a bit of refactoring on the llvm-flow project (which depends on llvm-block), along with adding some test coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: replace std::vector<collist*> with std::map or std::unordered_map

2 participants