LibJS: Cache ASCII-to-UTF-16 source conversion for Rust compilation

The Rust FFI requires UTF-16 source data, so ASCII-stored source code
must be widened to UTF-16. Previously, this conversion was done into a
temporary buffer on every call to compile_function, meaning the entire
source file was converted for each lazily-compiled function. For large
modules with many functions, this caused heavy spinning.

Move the conversion into SourceCode::utf16_data() which lazily converts
and caches the result once per source file. Subsequent compilations of
functions from the same file reuse the cached data.
This commit is contained in:
Andreas Kling
2026-02-24 22:07:27 +01:00
committed by Andreas Kling
parent a7d1c4baa6
commit 4b47245e99
Notes: github-actions[bot] 2026-02-24 23:01:57 +00:00
3 changed files with 27 additions and 29 deletions

View File

@@ -24,6 +24,8 @@ public:
Utf16View const& code_view() const { return m_code_view; }
size_t length_in_code_units() const { return m_length_in_code_units; }
u16 const* utf16_data() const;
SourceRange range_from_offsets(u32 start_offset, u32 end_offset) const;
private:
@@ -39,6 +41,10 @@ private:
// line:column they map to. This can then be binary-searched.
void fill_position_cache() const;
Vector<Position> mutable m_cached_positions;
// Cached UTF-16 widening of ASCII source data, lazily populated by
// utf16_data() for use by the Rust compilation pipeline.
Vector<u16> mutable m_utf16_data_cache;
};
}