Skip to content

Conversation

@kdy1
Copy link

@kdy1 kdy1 commented May 14, 2025

In turbopack, we serialize some large types using pot. The time complexity of addition is O(log N) for lookup and O(N) for insertion. I want to check if it is possible to improve it.

@kdy1 kdy1 changed the title perf: Improve time complexity for find_or_add_str perf: Improve time complexity for find_or_add May 14, 2025
// not changing. To avoid string comparisons, we're going to use the
// address of the str in the map.
let symbol_address = symbol.as_ptr() as usize;
// Perform a binary search to find this existing element.

Choose a reason for hiding this comment

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

nit: update comment

let id = entries.len() as u32;
let start = symbols.len();
symbols.push_str(symbol);
entries.insert(insert_at, (start..symbols.len(), id));

Choose a reason for hiding this comment

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

wont you have the same 'insert' concern here? whenever we insert a new static string via find_or_insert we should also be inserting a new string here (since I'm pretty sure the rust compiler deduplicates string constants).

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.

2 participants