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

exp/orderbook: Micro-optimization for paths search #4125

Merged
merged 1 commit into from
Dec 4, 2021

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Dec 3, 2021

Leftover from #4105

I just found it in a local branch and I realized I forgot to push it.

Very very minor stuff.

@2opremio 2opremio requested a review from tamirms December 3, 2021 20:15
@2opremio 2opremio merged commit 01ba901 into stellar:master Dec 4, 2021
@2opremio 2opremio deleted the microoptimization-paths-search branch December 4, 2021 18:37
@@ -423,7 +423,7 @@ func (graph *OrderBookGraph) FindFixedPaths(
maxAssetsPerPath int,
includePools bool,
) ([]Path, uint32, error) {
target := map[int32]bool{}
target := make(map[int32]bool, len(destinationAssets))
for _, destinationAsset := range destinationAssets {
destinationAssetString := destinationAsset.String()
target[graph.assetStringToID[destinationAssetString]] = true
Copy link
Member

@leighmcculloch leighmcculloch Dec 4, 2021

Choose a reason for hiding this comment

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

If this map is being used as a set where every entry has a value of true, there might also be a gain in converting the type to map[int32]struct{} since an empty struct consumes no memory while a book does. Not sure if the gain will be meaningful, but mentioning just in case.
https://dave.cheney.net/2014/03/25/the-empty-struct

Copy link
Member

Choose a reason for hiding this comment

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

Actually, for maps this might actually result in more allocations 🤔 TIL.

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