<br><br><div class="gmail_quote">On Wed, Feb 8, 2012 at 11:09, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le mercredi 08 février 2012 à 11:01 -0500, Brett Cannon a écrit :<br>
<div><div class="h5">><br>
><br>
> On Tue, Feb 7, 2012 at 17:42, Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>><br>
> wrote:<br>
> On Tue, 7 Feb 2012 17:24:21 -0500<br>
> Brett Cannon <<a href="mailto:brett@python.org">brett@python.org</a>> wrote:<br>
> ><br>
> > IOW you want the sys.modules case fast, which I will never<br>
> be able to match<br>
> > compared to C code since that is pure execution with no I/O.<br>
><br>
><br>
> Why wouldn't continue using C code for that? It's trivial<br>
> (just a dict<br>
> lookup).<br>
><br>
><br>
> Sure, but it's all the code between the function call and hitting<br>
> sys.modules which would also need to get shoved into the C code. As I<br>
> said, I have not tried to optimize anything yet (and unfortunately a<br>
> lot of the upfront costs are over stupid things like checking if<br>
> __import__ is being called with a string for the module name).<br>
<br>
</div></div>I guess my point was: why is there a function call in that case? The<br>
"import" statement could look up sys.modules directly.<br></blockquote><div><br></div><div>Because people like to do wacky stuff with their imports and so fully bypassing __import__ would be bad.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Or the built-in __import__ could still be written in C, and only defer<br>
to importlib when the module isn't found in sys.modules.<br>
Practicality beats purity.</blockquote><div><br></div><div> It's a possibility, although that would require every function call to fetch the PyInterpreterState to get at the cached __import__ (so the proper sys and imp modules are used) and I don't know how expensive that would be (probably as not as expensive as calling out to Python code but I'm thinking out loud).</div>
</div>