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

[performance] Too many closed() checkings #45748

Closed
wojtekwalczak mannequin opened this issue Nov 8, 2007 · 7 comments
Closed

[performance] Too many closed() checkings #45748

wojtekwalczak mannequin opened this issue Nov 8, 2007 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@wojtekwalczak
Copy link
Mannequin

wojtekwalczak mannequin commented Nov 8, 2007

BPO 1407
Nosy @gvanrossum, @amauryfa, @pitrou, @tiran, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-02-28.18:11:10.581>
created_at = <Date 2007-11-08.20:30:33.046>
labels = ['interpreter-core', 'library', 'performance']
title = '[performance] Too many closed() checkings'
updated_at = <Date 2009-02-28.18:11:10.580>
user = 'https://bugs.python.org/wojtekwalczak'

bugs.python.org fields:

activity = <Date 2009-02-28.18:11:10.580>
actor = 'pitrou'
assignee = 'none'
closed = True
closed_date = <Date 2009-02-28.18:11:10.581>
closer = 'pitrou'
components = ['Interpreter Core', 'Library (Lib)']
creation = <Date 2007-11-08.20:30:33.046>
creator = 'wojtekwalczak'
dependencies = []
files = []
hgrepos = []
issue_num = 1407
keywords = []
message_count = 7.0
messages = ['57275', '57276', '57320', '68151', '68157', '82926', '82932']
nosy_count = 6.0
nosy_names = ['gvanrossum', 'amaury.forgeotdarc', 'pitrou', 'christian.heimes', 'wojtekwalczak', 'benjamin.peterson']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'resource usage'
url = 'https://bugs.python.org/issue1407'
versions = ['Python 3.0']

@wojtekwalczak
Copy link
Mannequin Author

wojtekwalczak mannequin commented Nov 8, 2007

For debugging reasons I have added a simple line to PyObject_Call()
function in Objects/abstract.c:
printf("%s.%s\n", func->ob_type->tp_name, PyEval_GetFuncName(func));
Now, after compiling python and running interpreter with simple
print() call I receive this:
Python 3.0a1 (py3k, Nov  6 2007, 19:25:33)
[GCC 4.1.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print('!',end='')
builtin_function_or_method.print
method.write
function.write
function.closed
function.closed
builtin_function_or_method.ascii_encode
function.closed
function.closed
!method.write   # here it goes again for 'end' parameter
function.write
function.closed
function.closed
builtin_function_or_method.ascii_encode
function.closed
builtin_function_or_method.displayhook
>>>

Note that there can be something going on between one function.closed
and the next one, because not every piece of code gets called by
PyObject_Call(), but still - isn't it checking if stream is closed a
bit too often?

Regards,
Wojtek Walczak

@wojtekwalczak wojtekwalczak mannequin added build The build process and cross-build performance Performance or resource usage labels Nov 8, 2007
@tiran
Copy link
Member

tiran commented Nov 8, 2007

The problem should be addressed after the last alpha during the
optimization and cleanup phase.

@tiran tiran added interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir and removed build The build process and cross-build labels Nov 8, 2007
@gvanrossum
Copy link
Member

To find out what really happens, use pdb to step through the example.
This gives much better insight than adding a printf() call to
PyObject_Call(). I've notice myself when stepping through I/O that there
are a lot of checks for closed -- this may have to do with the stacking
text -> buffer -> binary though. I've also noticed overridden isinstance
checks in abc.py being called, which surprised me slightly. I haven't
had time to look into this further though.

@pitrou
Copy link
Member

pitrou commented Jun 13, 2008

Is this issue still valid?

@amauryfa
Copy link
Member

I reproduce almost the same output.
"function.closed" often come in pair, because TextIOWrapper.closed is a
property which delegates to self.buffer.closed

I think that the first check in TextIOWrapper.write() is not necessary:
self.buffer.write(b) will also check for "self.buffer.closed", and there
is not much code in-between. The only side-effect is the decoder state.

@benjaminp
Copy link
Contributor

Does io in C help with this?

@pitrou
Copy link
Member

pitrou commented Feb 28, 2009

Closing, as I don't think there's any point trying to micro-optimize the
Python version.

@pitrou pitrou closed this as completed Feb 28, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

5 participants