Box.update is slow
See original GitHub issueIs Box.update supposed to be much slower than dict.update? I expected the performance to be comparable, and ran into trouble. The code below shows the timing for dict.update and Box. .update
import random
import box
import string
import time
def random_string(N):
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=N))
a = dict((random_string(64), 0) for i in range(10**3))
for i in a:
a[i.upper()] = 0
b = box.Box(dict((random_string(64), 0) for i in range(10)))
c = dict((random_string(64), 0) for i in range(10))
st = time.time()
c.update(a)
et = time.time()
print(et - st)
st = time.time()
b.update(a)
et = time.time()
print(et - st)
Output:
2.09808349609375e-05
4.840667724609375
With
Python 3.7.5 (default, Nov 1 2019, 02:16:32)
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Box Edit very slow with Microsoft Word since recent update
I've been using Box Edit for years and since the last Microsoft Office update it takes a long time to save a document....
Read more >Troubleshoot slow game or app downloads
Learn how to troubleshoot slow game or app downloads on your Xbox console. ... The progress bar for your download or update hasn't...
Read more >Fix Your Slow Rockchip Android Box by Installing a ... - YouTube
Want to fix your broken Rockchip Android Box but unfortunately, you were not able to back up your device? Or do you simply...
Read more >MiBox 2303 update issue - slow performance after sleep
After the 2303 update my box is pretty much useless after sleep. It's so slow that I can't use it unless I reboot...
Read more >Troubleshooting issues with Box Sync
Box Sync is slow or won't stop "Scanning Files" · Find a folder you'd like to unsync, and right-click on it. · Click...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The above was tested with Box 3.4.6, while in 4.0.4
Box.update
is closer todict.update
and the performance is much better. Sorry for the confusion. The 3.4.6 version ofBox.update
lives on inBox.merge_update
. ForBox.merge_update
the performance is still very slow, the same as for the oldBox.update
in 3.4.6. See the code below. This performance issue is a consequence of__setattr__
being slow because of_conversion_checks
iterating over all keys in the dictionary on every call of__setattr__
. This also seems to be the case for__delitem__
, and__getattr__
. In practice this means that the basic operations (creates, lookup, updates, deletions) ofBox
have the same performance as a list. The below code shows that merge_update is considerably slower thandict.update
in 4.0.4.By using some extra internal bookkeeping data in
Box
it is possible to get performance comparable todict
.4.2.0 is now released, so going to close this issue hoping it is fixed, but if there are any issues let me know!
Thanks for all the help!