Add a page detailing the time complexity of operations on built-in types - #154363
Conversation
Documentation build overview
95 files changed ·
|
picnixz
left a comment
There was a problem hiding this comment.
Iteration is, AFAICT, always O(n) so we can group that under a common table. Likewise, getting the length of a sized object is O(1).
I think it's better to keep pythonic exmaples as well. "d[key]" is mucher better than "get item" IMO.
When I read "the non-mtating operations below", it also rings "the opertaions below are all non-mutating". Instead, I suggest to add some * if the opertaion is mutating and explain that at the beginning of the document.
While it would make the tables shorter, it's not so straightforward unfortunately. There are subtle differences, see footnote six. I also think that reference pages are scanned, not read linearly. As such, I'd prefer to keep them where they are. |
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
eendebakpt
left a comment
There was a problem hiding this comment.
I am +0.5 in this. I like to the idea, but it will take time to maintain and it is not clear to me where to draw the line when more additions are requested (e.g. memory complexity, alternatives, more detailed descriptions, more references).
|
FTR the Qt help pages once had a page for complexty of operations of their STL containers, so it might be worth reading them if you need precedents in other languages. I do not know if those pages still exist as they were available for Qt5 dirdctly in the Qt Creator IDE. |
|
I found back the link: https://doc.qt.io/qt-6/containers.html#algorithmic-complexity |
|
Thanks Pieter, Bénédikt and Hugo for the reviews ❤️ ! |
picnixz
left a comment
There was a problem hiding this comment.
This looks better but can you comment with saying what you deferred. I don't really understand why we should deferring some additions as this would create un-necessary future commits.
|
This has gotten four approvals, so I plan to merge this tomorrow. Please let me know if you'd like time to review, and I can wait. |
I have deferred adding various operations (we'll need to go through all of them, not just those mentioned in reviews here) for the reasons I outlined in #154363 (comment) (it took me quite a while to get to that comment, which I think is another reason for deferring). If we land the initial structure and design, we can iterate on the operations in follow ups. It would also be nice to get some user feedback once this goes live, to see if we should make any larger changes. |
We follow Diátaxis for the docs which recommends incremental steps rather than big bangs, which frequently stall and end up unmerged. https://diataxis.fr/how-to-use-diataxis/#work-one-step-at-a-time |
|
Thanks @StanFromIreland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-156326 is a backport of this pull request to the 3.15 branch. |
|
🎉 |
|
Thanks to everyone who contributed! This was a pretty considerable effort, and it took some time, but it has finally landed! |
…t-in types (GH-154363) (#156326) Add a page detailing the time complexity of operations on built-in types (GH-154363) (cherry picked from commit c3f7c33) Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Ned Batchelder <ned@nedbatchelder.com> Co-authored-by: dgpb <3577712+dg-pb@users.noreply.github.com>
|
Thanks @StanFromIreland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @StanFromIreland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Sorry, @StanFromIreland, I could not cleanly backport this to |
|
GH-156337 is a backport of this pull request to the 3.14 branch. |
|
|
GH-156338 is a backport of this pull request to the 3.13 branch. |
Inspired by @nedbat's post on Discourse:
The page's location isn't ideal, but we don't have a better place for it currently. We discussed this at the last Docs Community meeting, but didn't come up with a better place to put it, and creating new top level sections is in my opinion, out of scope (as we'd need to move other pages as well). If it's desired we can do it in a future PR.
I spend a while considering how to best present time complexity here, avoiding complexity ;-) The wiki pages splits it into amortised, worst, best and averages cases (each type had a selection of those), but I think that it would be too confusing for readers. As such I give the average case, and put the details in the prose/footnotes.
The numbers are, hopefully, correct, as I don't think I missed any quirks (at least I don't know of any ;-). But I'd appreciate a review from the experts here, maybe Serhiy or Tim could please take a peek?