[IronPython] Improving performance with stronger typing
Ben Blair
benblair at gmail.com
Mon Jun 5 22:32:54 CEST 2006
Hi,
One of the things I'm using IP for is to allow users to define
functions on CLR objects. Overall, this works great, but I'd like to
improve the performance as much as possible, since sometimes these
functions are evaluated many thousands of times per second. I'd like
to know if there's a better way to get the performance I want from IP
the way it is, or if not how I can best contribute some optimizations
to the project.
It looks like internally, most CLR type instances are passed around as
objects. When a particular type is needed, it is checked for, then the
instance is cast to the desired type. For example, evaluating "4+5"
calls Ops.Add(object x, object y), which does a bunch of type checking
and casting before doing an add. Ideally, when the input types are
known, IL should be emitted to just do the add operation.
This would be especially useful when calling the generic
PythonEngine.Evaluate<> method to get a strongly typed delegate for a
python function. In that case, the types will all be known at the time
Evaluate is called, so a type-specific version of the function could
be generated. Because that type information is already passed to
Evaluate<> (but currently discarded), I don't think any public
interfaces would have to change.
There are a couple of approaches I could try, but before I get started
I wanted to see if there were any existing ideas out there about how
to do this.
Thanks,
- Ben Blair
More information about the Ironpython-users
mailing list