Skip to content

use trait upcasting and drop the as_any/as_any_mut boilerplate#7220

Open
a10y wants to merge 1 commit intodevelopfrom
aduffy/asany
Open

use trait upcasting and drop the as_any/as_any_mut boilerplate#7220
a10y wants to merge 1 commit intodevelopfrom
aduffy/asany

Conversation

@a10y
Copy link
Copy Markdown
Contributor

@a10y a10y commented Mar 31, 2026

Since Rust 1.86 (which is before our MSRV) there has been builtin trait upcasting, meaning instead of forcing all our traits to have a dummy fn as_any(&self) -> &dyn Any methods with trivial impls, we can instead just take a pointer to the trait object and do as &dyn Any.

This reduces the amount of boilerplate in trait impls, which is nice. Another benefit is that in the past blanket impls like SessionVar would end up getting pulled in for dispatch of calls to as_any() which has caused me frustration. Now the dispatch is clearer.

This isn't a breaking change b/c it doesn't touch the VTables, which is the implementer surface area

@a10y a10y requested review from AdamGS and joseph-isaacs March 31, 2026 15:54
@a10y a10y added the changelog/chore A trivial change label Mar 31, 2026
@a10y a10y enabled auto-merge (squash) March 31, 2026 16:02
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 31, 2026

Merging this PR will degrade performance by 75.14%

❌ 9 regressed benchmarks
✅ 384 untouched benchmarks
⏩ 2235 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation take_indices[(100000, 1024)] 246.4 µs 970.8 µs -74.62%
Simulation take_indices[(100000, 16)] 747.1 µs 1,409.5 µs -47%
Simulation take_indices[(10000, 256)] 68.8 µs 139.2 µs -50.55%
Simulation take_indices[(100000, 4)] 1.7 ms 2.2 ms -26.01%
Simulation take_indices[(10000, 4)] 207 µs 261.3 µs -20.78%
Simulation take_indices[(100000, 256)] 268.1 µs 989.1 µs -72.89%
Simulation take_indices[(10000, 16)] 116.3 µs 179.1 µs -35.1%
Simulation take_indices[(10000, 1024)] 66.4 µs 137.5 µs -51.67%
Simulation take_indices[(100000, 4096)] 244.6 µs 984.3 µs -75.14%

Comparing aduffy/asany (606ab92) with develop (5ce08ed)

Open in CodSpeed

Footnotes

  1. 2235 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.

@robert3005
Copy link
Copy Markdown
Contributor

it's interesting that this had changed execution of take benchmarks?

Signed-off-by: Andrew Duffy <andrew@a10y.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants