Skip to content

Reserve AllDelayed vector to upper bound ( of llvm::DenseMap ). #21865

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 1 commit into from
Jan 15, 2019

Conversation

shahzadlone
Copy link
Contributor

@shahzadlone shahzadlone commented Jan 15, 2019

File: [swift/lib/Parse/PersistentParserState.cpp]

Observing this code snipped closely in function, [void PersistentParserState::parseAllDelayedDeclLists()]:

for (auto &P: DelayedDeclListStates) {
    AllDelayed.push_back(P.first);
}

We observe that 'AllDelayed' gets maximum of DelayedDeclListStates.size() elements pushed into it.
So it is better to reserve 'vector AllDelayed' to that max size, to save reallocation cost.

I believe we can use size() on [DelayedDeclListStates], which is of type: llvm::DenseMap<IterableDeclContext *, std::unique_ptr<DelayedDeclListState>> because of the DenseMapIterator implementation of size() in class DenseMapBase.

Helpful Link: http://llvm.org/doxygen/DenseMap_8h_source.html#l00126

@swift-ci Please test

File: [swift/lib/Parse/PersistentParserState.cpp]

Observing this code snipped closely in function, [void PersistentParserState::parseAllDelayedDeclLists()]:
```
for (auto &P: DelayedDeclListStates) {
    AllDelayed.push_back(P.first);
}
```

We observe that 'AllDelayed' gets maximum of DelayedDeclListStates.size() elements pushed into it.
So it is better to reserve 'vector AllDelayed' to that max size, to save reallocation cost.

I believe we can use size() on [DelayedDeclListStates], which is of type: ```llvm::DenseMap<IterableDeclContext *, std::unique_ptr<DelayedDeclListState>>``` because of the ```DenseMapIterator``` implementation of size().
[http://llvm.org/doxygen/DenseMap_8h_source.html#l00126]
@jrose-apple jrose-apple requested a review from nkcsgexi January 15, 2019 02:12
Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Good catch!

@nkcsgexi
Copy link
Contributor

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit de91fb6 into swiftlang:master Jan 15, 2019
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