wbond / pybars3

Handlebars.js template support for Python 3 and 2
GNU Lesser General Public License v3.0
179 stars 46 forks source link

Performance enhancement by using string concat vs list joins. #21

Open justecorruptio opened 9 years ago

justecorruptio commented 9 years ago

Theoretically, appending to lists and the joining and the end should be faster; but empirically, we've found that just doing string concats is actually faster anywhere from 2x to 5x depending on the template.

wbond commented 9 years ago

Instead of repeatedly concating strings, could you try using cStringIO/BytesIO (Python 2/3)?

Additionally, from looking through the change, it seems you've mixed this performance tweak in with some other changes. I'd rather approach each change separately so we can evaluate what affects they may have. Specifically the change in order to pick() and __call__ to callable.

justecorruptio commented 9 years ago

I can pull the other changes not related to concats to a separate PR, although they're both changes that affect performance.

cStringIO is still slower :-/

justecorruptio commented 9 years ago

OK, I've reverted the the call -> callable and pick() order changes for now.

adamantike commented 5 years ago

@wbond @isaacdd would you consider merging this if conflicts are fixed?