Cpython optimization

Q

Qrees

Hello

As my Master's dissertation I chose Cpython optimization. That's why
i'd like to ask what are your suggestions what can be optimized. Well,
I know that quite a lot. I've downloaded the source code (I plan to
work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at
the code I've found comment's like "this can be optimized by..." etc.
but maybe you guide me what should I concentrate on in my work?

I've 6-7 month for this and If I create something decent I can
publish it.

Thank you in advance for any help
 
Q

Qrees

If you don't know yet, you could find interesting this project:

I know about this project. I'll have a look at it, but I'd like to
create something of my own.
They too are trying to improve CPython speed.

If you are thinking of language variations  that trade some flexiblity
for speed, you might be interested in Cython:

http://www.cython.org/

I was thinking about sacrificing some flexibility of Python and thank
you for pointing me to this project. I didn't about it.
As a simple and plain python user, I would value a version of cython that
can be used to built faster executables out of almost-python code (that
is python code with a few additional restructions). Maybe using typing
inference to avoid declaring explicitely the variable types.

Another interesting place to go is pypy :http://codespeak.net/pypy/dist/
pypy/doc/ . They too have developed a restriced version of python
(RPython, I think) which should be faster than CPython. They don't work
with CPython code base, but could give you ideas on what are the
bottlenecks of python as a language.

Ciao

I'd like to hear a word from developers, what they think about
this :).

BTW: My seminar deals with object oriented programming.
 
J

John Nagle

Qrees said:
Hello

As my Master's dissertation I chose Cpython optimization. That's why
i'd like to ask what are your suggestions what can be optimized. Well,
I know that quite a lot. I've downloaded the source code (I plan to
work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at
the code I've found comment's like "this can be optimized by..." etc.
but maybe you guide me what should I concentrate on in my work?

I've 6-7 month for this and If I create something decent I can
publish it.

Thank you in advance for any help

The Shed Skin people would welcome some help.

http://shed-skin.blogspot.com/

Shed Skin is a Python to C++ compiler with automatic type inference.
For the programs it can handle, it's the fastest Python implementation
by a large margin.

The basic restriction in Shed Skin is that, while you don't have to
declare types, each variable generally has to stay the same type
throughout its life. (Different subclasses of the same class are OK.)
This is enough to make huge speedups possible.

John Nagle
 
J

John Yeung

   The Shed Skin people would welcome some help.

       http://shed-skin.blogspot.com/

People? It's one guy. It apparently started out as a Master's thesis
as well. ;)

I am a great admirer of the Shed Skin project, and I would be as happy
as anyone to see it progress. However, it seems to me that Shed Skin
is at a stage where what it really needs is plain old "more work". (I
don't want to call it grunt work, but it's things like more testing,
implementing more library support, maintaining the Windows build,
etc. Very worthy and worthwhile work, but tough to pass off as
academic graduate work.)

To the original poster: I am not sure if this is too ambitious for
your time frame, but one thing many real-world Python users would LOVE
is for some way to get rid of the GIL (while still retaining thread
safety, single-core performance, etc.). If you could patch CPython to
make it GIL-less, I think you would have academically publishable
material as well as being a hero in the Python community. :D

John
 
M

MRAB

Olof Bjarnason wrote:
[snip]
A short question after having read through most of this thread, on the
same subject (time-optimizing CPython):

http://mail.python.org/pipermail/python-list/2007-September/098964.html

We are experiencing multi-core processor kernels more and more these
days. But they are all still connected to the main memory, right?

To me that means, even though some algorithm can be split up into
several threads that run on different cores of the processor, that any
algorithm will be memory-speed limited. And memory access is a quite
common operation for most algorithms.

Then one could ask oneself: what is the point of multiple cores, if
memory bandwidth is the bottleneck? Specifically, what makes one expect
any speed gain from parallelizing a sequential algorithm into four
threads, say, when the memory shuffling is the same speed in both
scenarios? (Assuming memory access is much slower than ADDs, JMPs and
such instructions - a quite safe assumption I presume)

[ If every core had it's own primary memory, the situation would be
different. It would be more like the situation in a distributed/internet
based system, spread over several computers. One could view each core as
a separate computer actually ]
Don't forget about the on-chip cache! :)
 
S

Stefan Behnel

Francesco said:
As a simple and plain python user, I would value a version of cython that
can be used to built faster executables out of almost-python code (that
is python code with a few additional restructions). Maybe using typing
inference to avoid declaring explicitely the variable types.

Sorry, type inference has already landed and will be in Cython 0.12. Plus,
you do not need to declare variables in Cython, but you may, if you choose to.

Stefan
 
S

Stefan Behnel

Qrees said:

I was thinking about sacrificing some flexibility of Python and thank
you for pointing me to this project. I didn't about it.
[...]
BTW: My seminar deals with object oriented programming.

It's actually not hard to extend the set of optimisations in Cython, and
it's plain object oriented programming against the parse tree. Basically
just finding a code pattern and transforming it into something that does
the same thing, but faster.

It's also a lot of fun, and it certainly feels good to know that your tiny
tweak just made tons of other programs a bit faster.

Stefan
 
G

geremy condra

Hello

As my Master's dissertation I chose Cpython optimization. That's why
i'd like to ask what are your suggestions what can be optimized. Well,
I know that quite a lot. I've downloaded the source code (I plan to
work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at
the code I've found comment's like "this can be optimized by..." etc.
but maybe you guide me what should I concentrate on in my work?

I've 6-7 month  for this and If I create something decent I can
publish it.

Thank you in advance for any help

Could always port it to CUDA ;)

Geremy Condra
 
T

Terry Reedy

Qrees said:
Hello

As my Master's dissertation I chose Cpython optimization. That's why
i'd like to ask what are your suggestions what can be optimized. Well,
I know that quite a lot. I've downloaded the source code (I plan to
work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at
the code I've found comment's like "this can be optimized by..." etc.
but maybe you guide me what should I concentrate on in my work?

2.6.3 is about to be replaced with 2.6.4, but even that will not have
improvements that have already been added to 3.x or 2.7. I strongly
suggest that you work with the 3.2 code, since there is then a maximal
chance that your improvements will actually be adopted.
tjr
 
S

Stefan Behnel

Olof said:
[snip]
A short question after having read through most of this thread, on the
same subject (time-optimizing CPython):

http://mail.python.org/pipermail/python-list/2007-September/098964.html

We are experiencing multi-core processor kernels more and more these
days. But they are all still connected to the main memory, right?

To me that means, even though some algorithm can be split up into
several threads that run on different cores of the processor, that any
algorithm will be memory-speed limited. And memory access is a quite
common operation for most algorithms.

Then one could ask oneself: what is the point of multiple cores, if
memory bandwidth is the bottleneck? Specifically, what makes one
expect any speed gain from parallelizing a sequential algorithm into
four threads, say, when the memory shuffling is the same speed in both
scenarios? (Assuming memory access is much slower than ADDs, JMPs and
such instructions - a quite safe assumption I presume)

Modern (multi-core) processors have several levels of caches that interact
with the other cores in different ways.

You should read up on NUMA.

http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access

Stefan
 
A

Antoine Pitrou

Le Fri, 23 Oct 2009 09:45:06 +0200, Olof Bjarnason a écrit :
So I think my first question is still interesting: What is the point of
multiple cores, if memory is the bottleneck?

Why do you think it is, actually? Some workloads are CPU-bound, some
others are memory- or I/O-bound.

You will find plenty of benchmarks on the Web showing that some workloads
scale almost linearly to the number of CPU cores, while some don't.
 
A

Antoine Pitrou

Le Fri, 23 Oct 2009 15:53:02 +0200, Olof Bjarnason a écrit :
This would be way to speed up things in an image processing algorithm:
1. divide the image into four subimages 2. let each core process each
part independently 3. fix&merge (along split lines for example) into a
resulting, complete image

Well, don't assume you're the first to think about that.
I'm sure that performance-conscious image processing software already has
this kind of tile-based optimizations.
(actually, if you look at benchmarks of 3D rendering which are regularly
done by "enthusiast" websites, it shows exactly that)

Antoine.
 
R

Roy Hyunjin Han

As my Master's dissertation I chose Cpython optimization. That's why
i'd like to ask what are your suggestions what can be optimized. Well,
I know that quite a lot. I've downloaded the source code (I plan to
work on Cpython 2.6 and I've downloaded 2.6.3 release). By looking at
the code I've found comment's like "this can be optimized by..." etc.
but maybe you guide me what should I concentrate on in my work?

I've 6-7 month for this and If I create something decent I can
publish it.

Hi Qrees,

Have you heard of the Unladen Swallow project? It is an optimization
branch of CPython. Perhaps you can talk to some of the people working on
the project. http://code.google.com/p/unladen-swallow/

RHH


--
Get customized Python tutorials and live instruction for your business,
research or programming problem
Tuesday November 17 2009 6:30pm – 10pm
NYC Seminar and Conference Center (71 W 23rd St @ 6th Ave, New York, NY)
11/12 slots available for $30 each
http://invisibleroads.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top