-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] fix: remove DictEntry.__copyinit__
in Dict
methods (Pointer
, speed up)
#3824
Open
rd4com
wants to merge
2
commits into
modularml:nightly
Choose a base branch
from
rd4com:fix_speedup_dict
base: nightly
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🔥 benchmarksTheses are some small simple benchmarks with
from time import now
from collections import Dict
alias iteration_size = 1<<8
def main():
var result: Int=0
var start = now()
var stop = now()
small = Dict[Int, Int]()
start = now()
for x in range(100):
for i in range(iteration_size):
small[i]=i
for i in range(iteration_size):
result += small.pop(i)
stop = now()
print(stop-start, result)
start = now()
for x in range(100):
small = Dict[Int, Int]()
for i in range(iteration_size):
small[i]=i
for i in range(iteration_size):
result += small[i]
stop = now()
print(stop-start, result)
start = now()
for x in range(100):
small2 = Dict[Int, String]()
@parameter
for i in range(iteration_size):
alias tmp = str(i)
small2[i]=tmp
for i in range(iteration_size):
result += len(small2[i])
stop = now()
print(stop-start, result)
small2 = Dict[Int, String]()
start = now()
for x in range(100):
@parameter
for i in range(iteration_size):
alias tmp = str(i)
small2[i]=tmp
for i in range(iteration_size):
result += len(small2.pop(i))
stop = now()
print(stop-start, result)
small2 = Dict[Int, String]()
@parameter
for i in range(iteration_size):
alias tmp = str(i)
small2[i]=tmp
start = now()
for x in range(100):
for i in range(iteration_size):
result += len(small2[i])
stop = now()
print(stop-start, result) |
This is awesome!!! |
JoeLoser
approved these changes
Dec 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
…nter`, speed up) Hello, this probably fixes some bug reports 🥳 it is also now faster because we use `Pointer` and it removes `__copyinit__` ( Many methods like `__getitem__` uses `_find_index`, it was doing `__copyinit__` on entries while iterating ) The result is also a speedup, especially on types that allocate memory, best speedup is probably for `V:Arc` :thumbsup It should also speedup `**kwargs`! Signed-off-by: rd4com <[email protected]>
rd4com
force-pushed
the
fix_speedup_dict
branch
from
December 4, 2024 16:34
a9a1eca
to
c18cfb6
Compare
Thanks ! ✅ Changes implemented
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello, this probably fixes some bug reports 🥳
it is also now faster because we use
Pointer
and it removes__copyinit__
Many methods like
__getitem__
uses_find_index
,it was doing
__copyinit__
on entries while iteratingThe result is also a speedup, especially on types that allocate memory,
best speedup is probably for
V:Arc
👍It should also speedup
**kwargs
!