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

Optimize ecovec![] macro #29

Merged
merged 1 commit into from
Aug 3, 2023
Merged

Conversation

Kmeakin
Copy link
Contributor

@Kmeakin Kmeakin commented Aug 3, 2023

LLVM is not smart enough to eliminate calls to EcoVec::reserve() even when they are unecessary thanks to earlier calls to EcoVec::reserve() or EcoVec::with_capacity(). This patch elimates them when the ecovec![] macro is used. There may be other unnecessary calls which can be elimated in future patches.

ecovec![1, 2, 3] results in 3 unecessary calls to EcoVec::reserve(). Fixed by forwarding to the From<[T; N]> impl.

ecovec![1; 42] results in 42 unecessary calls to EcoVec::reserve(). Fixed by adding EcoVec::push_unchecked() function for when we know resizing is unnecessary.

src/vec.rs Outdated Show resolved Hide resolved
@laurmaedje
Copy link
Member

Originally, I planned to make a release today so that EcoVec::new constness is available for use through crates.io. If you plan to submit further PRs, I would wait with this.

LLVM is not smart enough to eliminate calls to `EcoVec::reserve()` even when
they are unecessary thanks to earlier calls to `EcoVec::reserve()` or
`EcoVec::with_capacity()`. This patch elimates them when the `ecovec![]` macro
is used. There may be other unnecessary calls which can be elimated in future
patches.

`ecovec![1, 2, 3]` results in 3 unecessary calls to `EcoVec::reserve()`. Fixed
by forwarding to the `From<[T; N]>` impl.

`ecovec![1; 42]` results in 42 unecessary calls to `EcoVec::reserve()`. Fixed by
adding `EcoVec::push_unchecked()` function for when we know resizing is
unnecessary.
@laurmaedje laurmaedje merged commit 0314c03 into typst:main Aug 3, 2023
4 checks passed
@laurmaedje
Copy link
Member

Thank you!

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.

2 participants