question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Box.update is slow

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jkyllingcommented, Feb 22, 2020

The above was tested with Box 3.4.6, while in 4.0.4 Box.update is closer to dict.update and the performance is much better. Sorry for the confusion. The 3.4.6 version of Box.update lives on in Box.merge_update. For Box.merge_update the performance is still very slow, the same as for the old Box.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) of Box have the same performance as a list. The below code shows that merge_update is considerably slower than dict.update in 4.0.4.

By using some extra internal bookkeeping data in Box it is possible to get performance comparable to dict.

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**2))
for i in a:
    a[i.upper()] = 0

b = box.Box(dict((random_string(64), 0) for i in range(10**3)))
c = dict((random_string(64), 0) for i in range(10**3))

st = time.time()
c.update(a)
et = time.time()
print(et - st)

st = time.time()
b.merge_update(a)
et = time.time()
print(et - st)
timing.py (END)
0reactions
cdgriffithcommented, Feb 26, 2020

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found