On Thu, Jul 08, 2010 at 02:10:57PM -0700, Shawn Walker wrote: > On 07/ 8/10 11:41 AM, [email protected] wrote: > >On Thu, Jul 08, 2010 at 11:02:50AM -0700, Shawn Walker wrote: > >>On 07/ 8/10 10:30 AM, [email protected] wrote: > >>>api.py: > >>> > >>> - line 1032 (and others): I've seen a bunch of instances of this: > >>> > >>> while tgt is not None: > >>> > >>> can this be re-written as? > >>> > >>> while tgt: > >>> > >>> Is it ever possible for this code 'ren_stems.get(stem, None)' to > >>> return a stem that's valid but evaluates to False? If not, it's > >>> simpler to omit the 'is' part of the check. > >> > >>In Python, testing for identity is much faster than testing for > >>"truthness" or "equality" because it simply compares memory > >>addresses. Since this code is a hot path, I've opted to take the > >>Python developer's recommendations to test for identity. > > > >It may be faster, but it comes at the expense of less readable code. > > I disagree; I actually find "if x is True" to be more readable since > it's immediately obvious I'm testing for True as opposed to a list > being populated, etc.
That can be more clear, but it gets annoying with statemens like, "if x is not True" (why not write, "if x is False" or "if not x"). > >Our vacationing language nurse has also been pretty stern about the > >format of comparisons. If this is the hot path, can you quantify how > >much faster this path runs with the 'is' comparison than the standard > >method? > > There's no difference greater than 1% in either direction that I can > measure. I'll remove the "is True" "is False" where it doesn't > matter, but all of the "is None" tests are intentional where I > actually only want that particular case. Ok, thanks. > >This also relies on an assumption that list allocation occurs when we > >assign the empty list. In C Python 2, the interpreter keeps a freelist > >of list objects, which are available for reuse without a call to > >malloc/free. I think it's also hypothetically feasible for an > >interpreter to keep a single empty list object, and only peform > >allocations when the caller actually adds items to the empty COW > >list. I would prefer that we only make assumptions about the underlying > >behavior of the runtime when it's absolutely necessary. > > I don't know what it's doing, but I've found that what I had here > actually increased memory usage by about 720KB consistently, which > makes no sense to me whatsoever. As such, I've changed this as you > mentioned above. Thanks for changing that. I'm just speculating, but perhaps you're seeing memory usage increase because you have a number of additional list objects on the freelist? -j _______________________________________________ pkg-discuss mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
