You probably can - dir is currently not optimized at all. Instead it's designed to ensure consistent results with member access. Due to that it does do more reflection than is strictly necessary. So you can do reflection and translate operator methods to __add__ and friends and it may be faster - but getting it 100% correct will be more challenging :) And then keeping it consistent going forward will be even more difficult.
-----Original Message----- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Michael Foord Sent: Sunday, May 24, 2009 6:21 AM To: Discussion of IronPython Subject: Re: [IronPython] Performance of dir Curt Hagenlocher wrote: > The first time you do a dir() of Form, we have to use Reflection to > introspect > - every member on Form > - every member on ContainerControl > - every member on ScrollableControl > - every member on Control > - every member on Component > (aka the inheritance hierarchy of Form :D ) > > After that, the members are all cached and subsequent access should be > quite fast. Yes, the second access is much faster. Thanks. I was hoping it was doing extra work and we could build a faster equivalent that only did the reflection, but oh well. :-) Michael > > On Sat, May 23, 2009 at 4:47 PM, Michael Foord > <fuzzy...@voidspace.org.uk <mailto:fuzzy...@voidspace.org.uk>> wrote: > > Michael Foord wrote: > > Hello all, > > On IronPython 2.0.1 the last line of this code takes ~4 > seconds the first time it is executed: > > >>> import clr > >>> clr.AddReference('System.Windows.Forms') > >>> from System.Windows.Forms import * > >>> dir(Form) > > Form.__dict__.keys() (which for a .NET type is equivalent) > takes ~1 second or less. What extra work is dir doing? (Is it > pulling in the xml docstrings?) > > > Actually they're not equivalent, my bad: > > >>> len(Form.__dict__) > 287 > >>> len(dir(Form)) > 540 > > Michael > > > Thanks > > Michael > > > > -- > http://www.ironpythoninaction.com/ > http://www.voidspace.org.uk/blog > > > _______________________________________________ > Users mailing list > Users@lists.ironpython.com <mailto:Users@lists.ironpython.com> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users@lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/blog _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com