cdgriffith / Box

Python dictionaries with advanced dot notation access
https://github.com/cdgriffith/Box/wiki
MIT License
2.61k stars 106 forks source link

Speed up crud operations. #134

Closed jkylling closed 4 years ago

jkylling commented 4 years ago

This fixes #129.

Because of _conversion_checks the complexity of a single __setattr__ is something like O(number_of_keys key_size). Hence the complexity of merge_update would be O(number_of_keys number_of_keys key_size). This comes as a surprise when you expect the complexity to be O(number_of_keys log(number_of_keys)).

This PR addresses this performance issue by using a dictionary mapping safe keys to old keys.

All the unit tests are passing. I am not familiar enough with Box to know if the use of __setattr__ and __setitem__ might lead to an inconsistent state of the Box, or if the unit tests cover this. Eventually, you might consider refactoring the code a bit (this is better done by the author who knows the code well).

pep8speaks commented 4 years ago

Hello @jkylling! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers:

Comment last updated at 2020-02-22 11:15:31 UTC