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

@@ -6,7 +6,6 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
#include <AK/Utf16FlyString.h>
@@ -92,6 +91,11 @@ struct SourceRecord {
u32 source_end_offset {};
};
struct SourceMapEntry {
u32 bytecode_offset {};
SourceRecord source_record {};
};
class JS_API Executable final : public Cell {
GC_CELL(Executable, Cell);
GC_DECLARE_ALLOCATOR(Executable);
@@ -143,7 +147,7 @@ public:
Vector<ExceptionHandlers> exception_handlers;
Vector<size_t> basic_block_start_offsets;
HashMap<size_t, SourceRecord> source_map;
Vector<SourceMapEntry> source_map;
Vector<LocalVariable> local_variable_names;
u32 local_index_base { 0 };