[squeak-dev] Re: The defaullt implementation of isEmpty might
do too much work
monty
monty2 at programmer.net
Thu Oct 27 23:23:28 UTC 2016
Or just make Collection>>#size a subclassResponsibiliity!
This will force implementors to give proper #size implementations that are usually O(1), which almost all do already. Bag could get the #do:-based #isEmpty as an optimization, or we could add a dedicated 'tally' inst var like other collections have and its #size could return that, making the default #size-based #isEmpty OK for it.
This is a compromise that addresses the concerns about the default Collection>>#isEmpty degrading linearly without a constant #size and the concerns about harming the performance of existing libraries and applications with custom collections that assume Collection>>#isEmpty is #size-based.
Please consider it.
> From: "Bert Freudenberg" <bert at freudenbergs.de>
> To: "Chris Muller" <ma.chris.m at gmail.com>, "The general-purpose Squeak developers list" <squeak-dev at lists.squeakfoundation.org>
> Subject: Re: [squeak-dev] Re: The defaullt implementation of isEmpty might do too much work
>
> On Thu, Oct 27, 2016 at 12:51 AM, Chris Muller <asqueaker at gmail.com[mailto:asqueaker at gmail.com]> wrote:
> In exchange for these blemishes, how many classes actually got benefit
> from inheriting the new implementation?
>
> | b |
> b := (1 to: 10000) asBag.
> [b isEmpty] bench
>
> before: : '5,540 per second. 181 microseconds per run.'
> now: '167,000 per second. 6 microseconds per run.'
> In my book that's a speedup worth having.
>
More information about the Squeak-dev
mailing list
|