-
Notifications
You must be signed in to change notification settings - Fork 993
Even faster stack traces for _connection.py #2836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
neoncube2
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
neoncube2:custom-iterator-for-faster-stack-trace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2018e49
Speed up connection by not asking for context when inspecting stack
neoncube2 5a92f4f
Formatting changes from the pre-commit hook
neoncube2 e973932
Also use inspect.stack(0) for the sync version of _connect
neoncube2 ebddce4
Fix pre-commit warnings
neoncube2 d68cacf
Fix pre-commit warnings
neoncube2 8dd96fe
Further improve the speed of retrieving stacktraces, by walking the s…
neoncube2 5ac20ef
Simplify test cases, so that they pass on all browsers
neoncube2 2745f55
Merge branch 'custom-iterator-for-faster-stack-trace' of https://gith…
neoncube2 20c0c6b
Omit get_frame_info() from the stack trace
neoncube2 2a08bac
Merge branch 'main' of https://github.com/neoncube2/playwright-python
neoncube2 99e6fea
Merge branch 'custom-iterator-for-faster-stack-trace' of https://gith…
neoncube2 411a841
Fuller type for `Generator`
neoncube2 3a97f3f
Use simpler type for Generator
neoncube2 b565b23
Merge branch 'microsoft:main' into custom-iterator-for-faster-stack-t…
neoncube2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking out loud - why does it need to be an Iterator in order to get the faster stacktraces? I assume that we call it only when we actually need it in line 546 and 566?
Also should we maybe use this similar function in playwright/_impl/_sync_base.pyplaywright/_impl/_sync_base.py:108` ? Then sync users - what the majority is - would benefit as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As to your question: In the original code, when we were calling
inspect.stack(0)
, it would immediately walk the entire stack (essentially, it would callframe.f_back
in a loop until there were no more frames). This is pretty expensive. By using an iterator, we delay walking the stack until we need it, and then we can only walk part of the stack (becauseframe.f_back
is only called when we need another frame)Basically: Calling
frame.f_back
is more expensive than one might think.Thanks for the heads up about
playwright/_impl/_sync_base.pyplaywright/_impl/_sync_base.py:108
! :) No wonder I couldn't find any information about__pw_stack__
... I thought it was being set byasyncio
, but it's actually being set by this package! XDLet me take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mxschmitt Now that I'm working on this again, I see what you mean about the iterator. I think that once I merge the logic in
_sync_base.py
and_connection.py
, this PR should be a lot cleaner (and faster!) :)