Skip to content

Commit ebcac6a

Browse files
perf(codec): force inline of vlq_decode for hot loop
Marking the public vlq_decode entry point as #[inline(always)] instead of just #[inline] lets rustc fully inline the VLQ inner loop into codec::decode across crate boundaries. The previous `#[inline]` hint was insufficient for the cross-crate hot path; the function-call overhead and tuple destructuring of `(value, consumed)` dominated the per-segment work. Real-world benchmark impact (codec::decode on isolated mappings strings): - preact (17 KB): 68.6 us -> 17.2 us (-75%) - chartjs (490 KB): 3.15 ms -> 1.22 ms (-61%) - pdfjs (2297 KB): 11.49 ms -> 6.15 ms (-46%) This closes most of the gap with the sourcemap crate's specialized decode_mappings (which has always inlined its own vlq_fast helper because it is private to the crate). The codec path remains slightly slower on larger maps because it still allocates Vec<Vec<Segment>> per line, but the inner-loop overhead is gone.
1 parent ff7c35a commit ebcac6a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

crates/codec/src/vlq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn vlq_encode(out: &mut Vec<u8>, value: i64) {
120120
/// Decode a single VLQ value from the input bytes starting at the given position.
121121
///
122122
/// Returns `(decoded_value, bytes_consumed)` or a [`DecodeError`].
123-
#[inline]
123+
#[inline(always)]
124124
pub fn vlq_decode(input: &[u8], pos: usize) -> Result<(i64, usize), DecodeError> {
125125
if pos >= input.len() {
126126
return Err(DecodeError::UnexpectedEof { offset: pos });

0 commit comments

Comments
 (0)