[Twisted-Python] Returning a deferred, maybe

James Y Knight foom at fuhm.net
Fri Jun 16 11:19:50 EDT 2006


On Jun 15, 2006, at 11:01 PM, Jean-Paul Calderone wrote:

> On Thu, 15 Jun 2006 22:53:22 -0400, glyph at divmod.com wrote:
>> [snip]
>>
>> Which reminds me.  Somebody really *should* be trying to get that  
>> C deferred stuff James did into Twisted proper; one Deferred for  
>> every locateChild sounds excruciatingly expensive for long URLs,  
>> as the code currently stands.
>>
>
> FWIW, last I checked, it was an insignificant performance  
> improvement over
> the current Deferred implementation, at least for web2.

Which is not all that surprising, as web2 doesn't make very many  
deferreds. The optimization of not returning a deferred when you have  
an immediate result is not really so minor if you'd otherwise be  
making a ton of them.

However, be careful, it's possible that in some cases the ambiguous  
result is actually slower, as "isinstance" turns out to be quite an  
expensive operation. So if you end up returning the deferred/result  
out multiple levels, testing at each level, at some point all the  
isinstance calls add up to be slower than just always returning a  
deferred.

James





More information about the Twisted-Python mailing list