Skip to content

date: reduce malloc#10992

Closed
oech3 wants to merge 2 commits intouutils:mainfrom
oech3:date-malloc
Closed

date: reduce malloc#10992
oech3 wants to merge 2 commits intouutils:mainfrom
oech3:date-malloc

Conversation

@oech3
Copy link
Contributor

@oech3 oech3 commented Feb 17, 2026

Closes #10702 as not planned.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 17, 2026

Merging this PR will not alter performance

✅ 10 untouched benchmarks
⏩ 316 skipped benchmarks1


Comparing oech3:date-malloc (5dc11d9) with main (b439534)

Open in CodSpeed

Footnotes

  1. 316 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@oech3 oech3 force-pushed the date-malloc branch 4 times, most recently from b98d0bc to b6d2fb5 Compare February 17, 2026 10:01
@oech3 oech3 force-pushed the date-malloc branch 2 times, most recently from cef8430 to 5dc11d9 Compare February 17, 2026 10:08
}
}

map.shrink_to_fit();
Copy link
Contributor

Choose a reason for hiding this comment

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

does shrink_to_fit reallocate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depending on allocator? But just once.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can avoid reallocation and add something like:

debug_assert!(
    map.capacity() <= map.len().next_power_of_two(),
    "HashMap capacity {} exceeds next power of two {} for length {}",
    map.capacity(),
    map.len().next_power_of_two(),
    map.len(),
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or just drop?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have some check that we weren't over allocating, if there is a possibility tzdata could shrink.

let mut map = HashMap::new();
fn build_tz_abbrev_map() -> AHashMap<String, String> {
// todo: optimiza initial size from actual data
let mut map = AHashMap::with_capacity_and_hasher(1024, Default::default());
Copy link
Contributor

Choose a reason for hiding this comment

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

move the magic number to TZ_ABBREV_CACHE_SIZE_HINT and document how it was determined?

Copy link
Contributor Author

@oech3 oech3 Feb 17, 2026

Choose a reason for hiding this comment

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

document how it was determined

I can't because I don't know how to determine it.

@oech3
Copy link
Contributor Author

oech3 commented Feb 17, 2026

2 test are good. But 2 test are bad:

  • file_tz_abbreviations 24.3 ms->24.4 ms
  • complex_relative_date 260 µs ->261.3 µs

@oech3 oech3 closed this Feb 17, 2026
@oech3 oech3 deleted the date-malloc branch February 17, 2026 19:00
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.

date: Include hash at compile time instead of HashMap-ping

2 participants