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

Merged
merged 5 commits into from
Feb 11, 2025

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 improve performances by 10.6%

Comparing esdrubal/trait_map_without_insert_for_type (247bf97) with master (475fd78)

Summary

⚡ 1 improvements
✅ 21 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
compile 5.1 s 4.6 s +10.6%

@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
@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.

sway-core/src/language/ty/declaration/function.rs Outdated Show resolved Hide resolved
@esdrubal esdrubal force-pushed the esdrubal/trait_map_without_insert_for_type branch from e55642d to 447a6e9 Compare February 6, 2025 16:31
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 f2f4fde to 284a008 Compare February 10, 2025 13:16
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.

LGTM

@JoshuaBatty
Copy link
Member

nice 10% speed increase :)

@IGI-111 IGI-111 enabled auto-merge (squash) February 11, 2025 15:43
@IGI-111 IGI-111 merged commit ac95d2d into master Feb 11, 2025
41 checks passed
@IGI-111 IGI-111 deleted the esdrubal/trait_map_without_insert_for_type branch February 11, 2025 16:01
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
4 participants