Skip to content
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

bpo-35196: optimize Squeezer's write() interception #10454

Merged
merged 26 commits into from
Jan 13, 2019

Conversation

taleinat
Copy link
Contributor

@taleinat taleinat commented Nov 10, 2018

This also cleans up and improves the testing of count_lines(), which has been significantly changed as part of this optimization.

https://bugs.python.org/issue35196

@terryjreedy
Copy link
Member

terryjreedy commented Dec 24, 2018

After partial first review:

Squeezer only applies to Shell, not editor or output windows. So it seems that ii should only be imported into pyshell and the handler only bound in PyShell. This itself could be fixed in another issue. However, some of the existing and proposed code

The Squeezer.init check "if isinstance(editwin, PyShell):" seems unneeded as the event handler function can only be called from the Shell write() and context menu.

The statement "Tab width is configurable" in Squeezer.count_lines is not true in IDLE and especially not in Shell. Configdialog lines 8 and 9, written in 2003 and 2005, say
"Note that tab width in IDLE is currently fixed at eight due to Tk issues.
Refer to comments in EditorWindow autoindent code for details."
I did not find anything about Tk issues in the autoindent code following editor line 1208. The comment may be obsolete, but since automatically expands user typed tabs, the point is mostly. So I think the count_lines_with_wrapping tabwidth parameter could be replaced with a local assignment.
tabwidth = 8
and all the testing involving a 'settable' tabwidth removed.

The linewidth stuff is ugly. Tk initially calculates pixel width from configured width in characters, (average) font character width, padding. Too bad it apparently does not itself do the reverse calculaton need for squeezer.

Lib/idlelib/squeezer.py Outdated Show resolved Hide resolved
Lib/idlelib/squeezer.py Outdated Show resolved Hide resolved
Lib/idlelib/squeezer.py Outdated Show resolved Hide resolved
Lib/idlelib/squeezer.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@taleinat taleinat force-pushed the bpo-35196/optimize_squeezer_write branch from 811214a to b77de8c Compare December 24, 2018 08:03
@taleinat
Copy link
Contributor Author

@terryjreedy, following your comment on the subject, I did some timings with and without the second short-circuit check and found that it had no significant effect even in the most extreme cases it was meant to optimize. I've removed it to avoid the unnecessary complexity.

@taleinat taleinat force-pushed the bpo-35196/optimize_squeezer_write branch from 9275b43 to 485d954 Compare December 24, 2018 12:27
@taleinat
Copy link
Contributor Author

@terryjreedy

So I think the count_lines_with_wrapping() tabwidth parameter could be replaced with a local assignment, tabwidth = 8, and all the testing involving a 'settable' tabwidth removed.

Done.

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@terryjreedy: please review the changes made to this pull request.

@terryjreedy
Copy link
Member

I am reviewing this and making a few changes now.

@taleinat
Copy link
Contributor Author

That assertion still fails on AppVeyor: zero_char_width is 8 before and after the reload() call. This is despite the test requiring the "gui" resource. See traceback below.

What should we do with this?

Test the reload() class-method.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\cpython\lib\idlelib\idle_test\test_squeezer.py", line 321, in test_reload
    self.assertGreater(squeezer.zero_char_width, orig_zero_char_width)
AssertionError: 8 not greater than 8```

@taleinat
Copy link
Contributor Author

That assertion still fails on AppVeyor

It passes locally on Windows 10, by the way.

@taleinat
Copy link
Contributor Author

That assertion still fails on AppVeyor

It fails on Travis-CI too :(

Do we just drop this assertion?

@terryjreedy
Copy link
Member

terryjreedy commented Jan 12, 2019

Cheryl's Ubuntu off-by-1 rounding failure and the CI no-change failures had different causes. I am experimenting with her suggested changes that avoid idleConf and expect to push something for the CI bots.

Whoops, hit wrong comment button.

@terryjreedy terryjreedy reopened this Jan 12, 2019
def load_font(self):
text = self.base_text
self.zero_char_width = \
Font(text, name=text.cget('font')).measure('0')
Copy link
Member

@terryjreedy terryjreedy Jan 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug. The font name is a string added to tk's registry of fonts. The tuple gets turned into a string. Since I cannot accept a suggestion after making myself assignee (contrary to (i) information popup, I will change 'name' to 'font' in the web editor and see if it changes CI bots. (Test still pass on my machine.)

@terryjreedy terryjreedy self-assigned this Jan 12, 2019
@terryjreedy
Copy link
Member

Thank you Cheryl, your suggestion works for the CI bots. After experimentation, I expect the new code should work even if a system does not have 'Courier'. On my machine, an unknown family is replaced by a default system font (Ariel, for me) and I assume that this is universal tk behavior.

Tal, go ahead and merge.

@taleinat taleinat merged commit 39a33e9 into python:master Jan 13, 2019
@miss-islington
Copy link
Contributor

Thanks @taleinat for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-bot
Copy link

GH-11541 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 13, 2019
The new functionality of Squeezer.reload() is also tested, along with some general
re-working of the tests in test_squeezer.py.
(cherry picked from commit 39a33e9)

Co-authored-by: Tal Einat <[email protected]>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Gentoo Installed with X 3.x has failed when building commit 39a33e9.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/103/builds/1964) and take a look at the build logs.
  4. Check if the failure is related to this commit (39a33e9) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/103/builds/1964

Click to see traceback logs
From https://github.com/python/cpython
 * branch                  master     -> FETCH_HEAD
Reset branch 'master'

Python/pystate.c: In function ‘_long_shared’:
Python/pystate.c:1483:18: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     data->data = (void *)value;
                  ^

/buildbot/tmp/tmpdir/tmplub9mdym/pip-18.1-py2.py3-none-any.whl/pip/_vendor/requests/status_codes.py:3: SyntaxWarning: invalid escape sequence \o
/buildbot/tmp/tmpdir/tmplub9mdym/pip-18.1-py2.py3-none-any.whl/pip/_vendor/requests/status_codes.py:3: SyntaxWarning: invalid escape sequence \o

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Gentoo Non-Debug with X 3.x has failed when building commit 39a33e9.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/99/builds/2024) and take a look at the build logs.
  4. Check if the failure is related to this commit (39a33e9) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/99/builds/2024

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.x.ware-gentoo-x86.nondebug/build/Lib/idlelib/idle_test/test_squeezer.py", line 310, in test_reload
    self.assertGreater(squeezer.zero_char_width, orig_zero_char_width)
AssertionError: 6 not greater than 6

----------------------------------------------------------------------

Ran 475 tests in 8.425s

FAILED (failures=1, skipped=3)


Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.x.ware-gentoo-x86.nondebug/build/Lib/idlelib/idle_test/test_squeezer.py", line 310, in test_reload
    self.assertGreater(squeezer.zero_char_width, orig_zero_char_width)
AssertionError: 6 not greater than 6

----------------------------------------------------------------------

Ran 475 tests in 5.916s

FAILED (failures=1, skipped=3)

@taleinat
Copy link
Contributor Author

The problematic test_reload() is failing on the Gentoo buildbots:

======================================================================
FAIL: test_reload (idlelib.idle_test.test_squeezer.SqueezerTest)
Test the reload() class-method.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.x.ware-gentoo-x86.nondebug/build/Lib/idlelib/idle_test/test_squeezer.py", line 310, in test_reload
    self.assertGreater(squeezer.zero_char_width, orig_zero_char_width)
AssertionError: 6 not greater than 6
----------------------------------------------------------------------``

@terryjreedy
Copy link
Member

terryjreedy commented Jan 13, 2019

I will open a new issue and PR to fix this, initially by disabling it. I approved the backport since I will follow with the initial fix and I want 3.7 in sync with master.

miss-islington added a commit that referenced this pull request Jan 13, 2019
The new functionality of Squeezer.reload() is also tested, along with some general
re-working of the tests in test_squeezer.py.
(cherry picked from commit 39a33e9)

Co-authored-by: Tal Einat <[email protected]>
@terryjreedy
Copy link
Member

Issue 35730, PR #11543.

@taleinat taleinat deleted the bpo-35196/optimize_squeezer_write branch January 14, 2019 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants