Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Dec 21, 2025

No description provided.

Summary

  4 files modified with Vec::with_capacity() optimizations:

  | File                                | Change                        | Capacity                                   |
  |-------------------------------------|-------------------------------|--------------------------------------------|
  | awk/interpreter/mod.rs:64           | gather_values                 | count as usize                             |
  | awk/interpreter/mod.rs:76           | print_to_string               | argc as usize                              |
  | text/cut.rs:129                     | cut_bytes                     | line.len()                                 |
  | cc/arch/x86_64/codegen.rs:1901      | stack_arg_indices             | insn.src.len()                             |
  | cc/ir/linearize.rs:841-845          | struct_params, complex_params | func.params.len()                          |
  | cc/arch/x86_64/codegen.rs:3737-3753 | 7 inline asm arrays           | operand_count, outputs.len(), inputs.len() |
@jgarzik jgarzik requested a review from Copilot December 21, 2025 00:10
@jgarzik jgarzik self-assigned this Dec 21, 2025
@jgarzik jgarzik added enhancement New feature or request cleanup labels Dec 21, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes memory allocation for HashMap and Vec collections by pre-allocating capacity where the size can be reasonably estimated, reducing the number of reallocations during runtime.

Key changes:

  • Pre-allocating HashMap capacity based on input sizes or reasonable defaults
  • Pre-allocating Vec capacity when the final size is known upfront
  • Adding named constants for default capacities to improve code maintainability

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tree/mv.rs Pre-allocate inode_map HashMap capacity based on sources length
text/sed.rs Pre-allocate counts HashMap capacity based on vec length
text/cut.rs Pre-allocate result Vec capacity based on input line length
sh/shell/mod.rs Add constant and pre-allocate saved_command_locations HashMap with default capacity
sh/shell/environment.rs Pre-allocate exported HashMap capacity based on global_scope size
cc/token/preprocess.rs Add constant and pre-allocate macros HashMap with default capacity
cc/symbol.rs Add constant and pre-allocate name_map HashMap with default capacity
cc/ir/linearize.rs Add constants and pre-allocate multiple HashMaps and Vecs with appropriate capacities
cc/arch/x86_64/codegen.rs Pre-allocate multiple Vec capacities based on computed operand counts
awk/interpreter/mod.rs Pre-allocate Vec capacities based on known count parameters

@jgarzik jgarzik merged commit 363db81 into main Dec 21, 2025
10 checks passed
@jgarzik jgarzik deleted the updates branch December 21, 2025 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants