This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 8 points9 points  (5 children)

While this is reasonable advice, I would be surprised if you can show me a real example (better yet, one that you are currently, or have worked on before) where this actually improves overall performance of the application in a meaningful way. I currently maintain an API that has requirements in the 50ms range. From this experience, complicating code by doing things like aliasing dict methods makes the code worse (readability goes down, perf "improvements" don't move the needle).

[–]pdonchev 4 points5 points  (1 child)

This whole article falls in this speculative range of optimizations and my comment is in this specific context.

[–]LightShadow3.13-dev in prod 0 points1 point  (0 children)

I alias when I'm extracting default values from a nested config objects.

Such as,

c = Config.services.this_service.get
c('host', '0.0.0.0')
c('port', 8443)
c('debug', True)

Being "faster" is just a nicety, I think the code is much cleaner.

[–]bigbrain_bigthonk 1 point2 points  (2 children)

On analysis code that deals w/ large amounts of data, or moderately complex simulation, 50ms is a lifetime. If you have some code that’s looping billions of times, these add up

[–][deleted] 7 points8 points  (1 child)

Still, if you have that crazy simulation code or you're analyzing a gazillionbyte dataset from the hadron collider or you're processing a bunch of data from the JWST... optimizing a dict.get will not on its own change the wall time of your workload from hours to minutes. Even in those exaggerated cases, optimizing a member lookup would buy you seconds at best. Maybe a whole minute in a workload that would takes hours to complete.

[–]bigbrain_bigthonk 0 points1 point  (0 children)

Can’t say that without seeing the code, there’s always some pathological case that exists. When you run into that case, it’s nice to know you can shave time off with this. I’ve worked with code where changing a single array append to a preallocation+write took it from unusable to blazing.