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

avoid zeroMem when resizing trivial seq:s #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arnetheduck
Copy link
Member

might as well grab a new sequence instead

when T is SomeNumber:
# `setLen` does costly zero:ing both when growing _and_ shrinking
if tgt.len > src.len or tgt.len < src.len div 4:
tgt = newSeqUninitialized[T](src.len)
Copy link
Contributor

Choose a reason for hiding this comment

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

Memory allocation and garbage collection is faster than skipping some memset(0) calls? Doesn't sounds universally true.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's true for large allocations above all because allocation doesn't depend that much on the size of the allocation - it seemed to give an improvement in vtune - see also nim-lang/Nim#19728 and nim-lang/Nim#19727

might as well grab a new sequence instead
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