Skip to content

Avoid temporary vectors in derive trait checks - #683

Merged
nunoplopes merged 3 commits into
masterfrom
perfloop-pr-open-bdm0awjaye
Nov 27, 2026
Merged

nunoplopes merged 3 commits into
masterfrom
perfloop-pr-open-bdm0awjaye

Conversation

@perfloop

@perfloop perfloop Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Each available derive-trait check builds a temporary vector just to pass repeated type arguments to rustc. Pass std::iter::repeat_n instead, avoiding that disposable storage while using the existing iterator-taking API.

The argument count still comes from tcx.generics_of(trait_def_id).count(). Trait filtering, result order, and the caller’s parameter environment are unchanged, including the parameter-environment handling added in #586. Both translation models continue through the same trait solver and IR serialization paths.

The allocation regression test in rule-preprocessor/src/semantic.rs calls the actual derive routine and detects restoration of the vector. It requires a release-mode test build; its allocator and observations are compiled only for tests.

This removes temporary argument-container allocations, not rustc’s trait-reference or solver allocations. Preprocessing latency has not been measured, so no time saving is claimed.

Cargo’s release-mode preprocessor test run reported 1 passed, 0 failed, and 0 ignored. Rust formatting and release Clippy checks passed for the changed preprocessor code. The ordinary rule-preprocessor CLI completed the shipped rule modules for each available translation model.

Case and evidence


Made by Perfloop.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@nunoplopes

Copy link
Copy Markdown
Contributor

@perfloop-agent remove all the test stuff; leave just the optimization.

@perfloop

perfloop Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The iterator substitution can stand alone; the test allocator, compiler callback, and allocation assertions do not need to ship.

@nunoplopes

Copy link
Copy Markdown
Contributor

The iterator substitution can stand alone; the test allocator, compiler callback, and allocation assertions do not need to ship.

ok, remove them then.

Removed test-related code for allocation counting and assertions from semantic.rs.
@nunoplopes
nunoplopes marked this pull request as ready for review November 27, 2026 08:50
@nunoplopes
nunoplopes merged commit 09d7859 into master Nov 27, 2026
9 checks passed
@nunoplopes
nunoplopes deleted the perfloop-pr-open-bdm0awjaye branch November 27, 2026 09:11
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.

2 participants