Skip to content
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

Removes TraitMap::insert_for_type. #6867

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

esdrubal
Copy link
Contributor

@esdrubal esdrubal commented Jan 28, 2025

Description

Some use cases require the compiler to call insert_implementation_for_type on every call of find_method_for_type.
This would double the compile time of a simple script. To avoid this we removed the TraitMap::insert_for_type. The TraitMap now only stores the original implementations and uses a less restrictive unify_check to get those that match the concrete implementations.

This significantly reduces the TraitMap's size and speeds up the lookup times. On the other hand, it also introduces a type substitution on every find_method_for_type.

A future PR will address the performance of doing type substitutions.

Fixes #5002.
Fixes #6858

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@esdrubal esdrubal added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Jan 28, 2025
@esdrubal esdrubal self-assigned this Jan 28, 2025
Copy link

codspeed-hq bot commented Jan 28, 2025

CodSpeed Performance Report

Merging #6867 will not alter performance

Comparing esdrubal/trait_map_without_insert_for_type (447a6e9) with master (5ed7cec)

Summary

✅ 22 untouched benchmarks

@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from 61fed08 to ee4d114 Compare February 4, 2025 11:35
@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from ee4d114 to 057d1ea Compare February 4, 2025 11:44
@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from 057d1ea to c3db20f Compare February 4, 2025 11:50
@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from c3db20f to f17481b Compare February 4, 2025 11:57
Some use cases require the compiler to call insert_implementation_for_type
on every call of find_method_for_type.
This would double the compile time of a simple script.
To avoid this we removed the TraitMap::insert_for_type. The TraitMap
now only stores the original implementations and uses a less restrictive
unify_check to get those that match the concrete implementations.

This reduces significantly the size of the TraitMap and speeds up the lookup times.
On the other hand, it also introduces a type substitution on every find_method_for_type.

A future PR will address the performance of doing type substitutions.
@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from f17481b to 0b6370a Compare February 4, 2025 11:59
@esdrubal esdrubal marked this pull request as ready for review February 4, 2025 12:37
@esdrubal esdrubal requested a review from a team as a code owner February 4, 2025 12:37
Copy link
Contributor

@jjcnn jjcnn left a comment

Choose a reason for hiding this comment

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

I'm not 100% I understand what's going on, but it looks ok.

The two comments I've made are mostly something that looks odd - I don't know if they're actual mistakes. Maybe it would be worth adding comments in those places to avoid future confusion.

Comment on lines +171 to +172
}
if engines
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be an else if? There's a risk you'll perform two insertions AFAICT.

.collect::<Vec<_>>();
if !matches.is_empty() {
type_id_type_subst_map
.insert(impl_type_parameter.type_id, matches[0].0.type_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised you only need to look at matches[0] and not the rest of the matches.

@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from e55642d to 447a6e9 Compare February 6, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
2 participants