Skip to content

Do manual trait casting #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 31, 2025
Merged

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Jun 20, 2025

This removes occurences of dyn Database internally where only the zalsas are needed for (hopefully) a perf increase.

Lastly it renames downcasting to upcasting, because thats what we are doing, dyn Database --downcast-> Concrete --upcast-->dyn CustomDatabaseTrait

Copy link

netlify bot commented Jun 20, 2025

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 8c0ec58
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/688b0099a8be6000084da634

Copy link

codspeed-hq bot commented Jun 20, 2025

CodSpeed Performance Report

Merging #922 will improve performances by 5.84%

Comparing Veykril:veykril/push-tsxunswownmm (8c0ec58) with master (f3dc2f3)

Summary

⚡ 1 improvements
✅ 11 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
new[InternedInput] 4.3 µs 4 µs +5.84%

@Veykril Veykril force-pushed the veykril/push-tsxunswownmm branch 4 times, most recently from 2073e08 to 28acf8c Compare June 20, 2025 09:13
@Veykril
Copy link
Member Author

Veykril commented Jun 20, 2025

Benchmarks look fairly noisy again to me

@MichaReiser
Copy link
Contributor

Not sure, 5% is a bit more than usual.

@Veykril
Copy link
Member Author

Veykril commented Jun 20, 2025

Well the increase seems to stem from ingredient fetching which means its likely the IngredientCache missing being more expensive after this

@Veykril Veykril force-pushed the veykril/push-tsxunswownmm branch 2 times, most recently from 0b13ad9 to e50ed3a Compare July 29, 2025 19:00
@Veykril
Copy link
Member Author

Veykril commented Jul 29, 2025

Okay the regression came from a dumb mistake

@Veykril Veykril marked this pull request as ready for review July 29, 2025 19:03
@Veykril Veykril changed the title Do manual trait upcasting instead of downcasting Do manual trait casting Jul 29, 2025
@MichaReiser MichaReiser requested a review from ibraheemdev July 30, 2025 06:54
@Veykril Veykril force-pushed the veykril/push-tsxunswownmm branch from e50ed3a to 523d4c8 Compare July 30, 2025 07:13
@Veykril
Copy link
Member Author

Veykril commented Jul 30, 2025

Some context for reviewing aid, there are couple of noisy changes (that I could've split out into separate commits, sorry):

  • downcasting being renamed to upcasting
  • replacing dyn Database args with Zalsa/ZalsaLocal, this allows getting rid of a few dynamic dispatches, mostly concerns the macro changes

}
}

/// Upcast to a `dyn Database`.
///
/// Only required because upcasts not yet stabilized (*grr*).
/// Only required because upcasting does not work for unsized generic parameters.
Copy link
Member Author

Choose a reason for hiding this comment

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

I am quite annoyed by this but that's a limitation of Rust, a &T of T: ?Sized + SomeTrait cannot be coerced to a &dyn SomeTrait (or a supertrait) due to T possibly being an unrelated unsized type like str

Copy link
Member

Choose a reason for hiding this comment

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

Can we add the Sized requirement?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, specifically this is used solely for attach which needs to take a dyn database of some form.

@Veykril Veykril force-pushed the veykril/push-tsxunswownmm branch from f553491 to 70bdaef Compare July 30, 2025 07:31
Copy link
Member

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

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

The changes to avoid dynamic dispatch make sense to me. I'm not sure about renaming the operation to upcasting. Upcasting would be going from a &dyn DatabaseView to &dyn Database, where Database is a supertrait of DatabaseView. What we're doing is going from a &dyn Database to a &dyn DatabaseView -- the other way around. It's similar to downcasting Any to a concrete type, but instead we're downcasting to a "more concrete" subtrait.

}
}

/// Upcast to a `dyn Database`.
///
/// Only required because upcasts not yet stabilized (*grr*).
/// Only required because upcasting does not work for unsized generic parameters.
Copy link
Member

Choose a reason for hiding this comment

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

Can we add the Sized requirement?

@Veykril
Copy link
Member Author

Veykril commented Jul 31, 2025

The changes to avoid dynamic dispatch make sense to me. I'm not sure about renaming the operation to upcasting. Upcasting would be going from a &dyn DatabaseView to &dyn Database, where Database is a supertrait of DatabaseView. What we're doing is going from a &dyn Database to a &dyn DatabaseView -- the other way around. It's similar to downcasting Any to a concrete type, but instead we're downcasting to a "more concrete" subtrait.

Hmm fair, I think i focused too much on the second step of the casting procedure, going from concrete back to dyn Trait.

@Veykril Veykril force-pushed the veykril/push-tsxunswownmm branch from 471f240 to 0b385e7 Compare July 31, 2025 05:28
@Veykril Veykril requested a review from ibraheemdev July 31, 2025 05:28
@Veykril Veykril force-pushed the veykril/push-tsxunswownmm branch from 0b385e7 to 8c0ec58 Compare July 31, 2025 05:35
@Veykril Veykril added this pull request to the merge queue Jul 31, 2025
Merged via the queue into salsa-rs:master with commit 211bc15 Jul 31, 2025
12 checks passed
@Veykril Veykril deleted the veykril/push-tsxunswownmm branch July 31, 2025 16:05
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.

3 participants