anvil-works / anvil-runtime

The runtime engine for hosting Anvil web apps
https://anvil.works/open-source
Other
874 stars 116 forks source link

Use map to improve speed of WrappedList init / extend by ~60% #76

Open benjaminwoods opened 7 months ago

benjaminwoods commented 7 months ago

Purpose

This PR improves the performance of WrappedList by using map.

Summary of changes

I used map and some short-circuiting to improve performance.

All code is commented, with docstrings, and typed where relevant.

Validation steps

✔️ Created an environment (for me, a Poetry environment, because I am using Python 3.10) ✔️ Installed anvil-runtime Python downlink, using path installation ✔️ Ran tests (see #75) in the environment. Confirmed that all tests pass. ✔️ Ran quick-and-dirty timing script

Speedup (before / after)
>> instantiation with 1000 elements:           1.6896897566622429
>> extending by 1000 elements:                 1.6881427085098548
>> appending 1000 elements:                    0.992154109612771
>> inserting 1000 elements:                    0.9807249483142917
>> deepcopy sqrt(1000) x sqrt(1000) elements:   0.962684461929972