LibJS: Replace source map HashMap with sorted Vector

Bytecode source map entries are always added in order of increasing
bytecode offset, and lookups only happen during error handling (a cold
path). This makes a sorted vector with binary search a better fit than
a hash map.

This change reduces memory overhead and speeds up bytecode generation
by avoiding hash table operations during compilation. Lookups remain
fast via binary search, and since source_range_at() is only called
when generating stack traces, the O(log n) lookup is acceptable.
This commit is contained in:
Andreas Kling
2026-01-26 17:51:53 +01:00
committed by Andreas Kling
parent d488f9f12f
commit 81bee185e6
Notes: github-actions[bot] 2026-02-06 11:03:57 +00:00
4 changed files with 23 additions and 11 deletions

View File

@@ -56,7 +56,7 @@ public:
BasicBlock const* finalizer() const { return m_finalizer; }
auto const& source_map() const { return m_source_map; }
void add_source_map_entry(u32 bytecode_offset, SourceRecord const& source_record) { m_source_map.set(bytecode_offset, source_record); }
void add_source_map_entry(u32 bytecode_offset, SourceRecord const& source_record) { m_source_map.append({ bytecode_offset, source_record }); }
[[nodiscard]] bool has_resolved_this() const { return m_has_resolved_this; }
void set_has_resolved_this() { m_has_resolved_this = true; }
@@ -75,7 +75,7 @@ private:
bool m_terminated { false };
bool m_has_resolved_this { false };
HashMap<size_t, SourceRecord> m_source_map;
Vector<SourceMapEntry> m_source_map;
size_t m_last_instruction_start_offset { 0 };
};