Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Can someone who knows better than me how it works (probably Steve) please put a function in druntime to clear the current thread's array appending cache? I need this for two reasons: 1. To make sure arrays I'm done with get GC'd. 2. To make it safe(r) to free arrays manually. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101118/f9d92d2a/attachment.html> |
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Simcha | Related question: can we make Appender a thin wrapper over arrays? It looks like improving "~=" caching is the right way to place effort.
Andrei
On 11/18/10 1:15 PM, David Simcha wrote:
> Can someone who knows better than me how it works (probably Steve) please put a function in druntime to clear the current thread's array appending cache? I need this for two reasons:
>
> 1. To make sure arrays I'm done with get GC'd.
>
> 2. To make it safe(r) to free arrays manually.
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Simcha | I plan to fix 1 soon (as discussed in your bug report). I forgot about 2, but the runtime function that deletes an array should remove it from the cache. (this is an easy fix). To get you running, this would be the contents of the requested function (must put the function in rt/lifetime.d): __blkcache[] = BlkInfo.init; -Steve > >From: David Simcha <dsimcha at gmail.com> >To: Discuss the phobos library for D <phobos at puremagic.com> >Sent: Thu, November 18, 2010 4:15:50 PM >Subject: [phobos] Clear appending cache? > >Can someone who knows better than me how it works (probably Steve) please put a function in druntime to clear the current thread's array appending cache? I need this for two reasons: > >1. To make sure arrays I'm done with get GC'd. > >2. To make it safe(r) to free arrays manually. > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101118/ae6351f1/attachment.html> |
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Appender is currently much faster than array appending because it has a dedicated place to store the array length/capacity. Simply wrapping arrays makes it much slower (which has a necessarily very convoluted way to lookup the block capacity). Or am I missing something?
-Steve
----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Thu, November 18, 2010 4:28:43 PM
> Subject: Re: [phobos] Clear appending cache?
>
> Related question: can we make Appender a thin wrapper over arrays? It looks like improving "~=" caching is the right way to place effort.
>
> Andrei
>
> On 11/18/10 1:15 PM, David Simcha wrote:
> > Can someone who knows better than me how it works (probably Steve)
> > please put a function in druntime to clear the current thread's array
> > appending cache? I need this for two reasons:
> >
> > 1. To make sure arrays I'm done with get GC'd.
> >
> > 2. To make it safe(r) to free arrays manually.
> >
> >
> >
> > _______________________________________________
> > phobos mailing list
> > phobos at puremagic.com
> > http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
|
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Schveighoffer | What is the efficiency difference? Can it be reduced?
Andrei
On 11/18/10 1:36 PM, Steve Schveighoffer wrote:
> Appender is currently much faster than array appending because it has a dedicated place to store the array length/capacity. Simply wrapping arrays makes it much slower (which has a necessarily very convoluted way to lookup the block capacity). Or am I missing something?
>
> -Steve
>
>
>
> ----- Original Message ----
>> From: Andrei Alexandrescu<andrei at erdani.com>
>> To: Discuss the phobos library for D<phobos at puremagic.com>
>> Sent: Thu, November 18, 2010 4:28:43 PM
>> Subject: Re: [phobos] Clear appending cache?
>>
>> Related question: can we make Appender a thin wrapper over arrays? It looks like improving "~=" caching is the right way to place effort.
>>
>> Andrei
>>
>> On 11/18/10 1:15 PM, David Simcha wrote:
>>> Can someone who knows better than me how it works (probably Steve)
>>> please put a function in druntime to clear the current thread's array
>>> appending cache? I need this for two reasons:
>>>
>>> 1. To make sure arrays I'm done with get GC'd.
>>>
>>> 2. To make it safe(r) to free arrays manually.
>>>
>>>
>>>
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Schveighoffer | I think we should actively discourage manual release of memory from the GC heap. We should instead facilitate use of malloc and free.
Andrei
On 11/18/10 1:33 PM, Steve Schveighoffer wrote:
> I plan to fix 1 soon (as discussed in your bug report).
>
> I forgot about 2, but the runtime function that deletes an array should remove it from the cache. (this is an easy fix).
>
> To get you running, this would be the contents of the requested function (must put the function in rt/lifetime.d):
>
> __blkcache[] = BlkInfo.init;
>
> -Steve
>
>
> *From:* David Simcha <dsimcha at gmail.com>
> *To:* Discuss the phobos library for D <phobos at puremagic.com>
> *Sent:* Thu, November 18, 2010 4:15:50 PM
> *Subject:* [phobos] Clear appending cache?
>
> Can someone who knows better than me how it works (probably Steve)
> please put a function in druntime to clear the current thread's
> array appending cache? I need this for two reasons:
>
> 1. To make sure arrays I'm done with get GC'd.
>
> 2. To make it safe(r) to free arrays manually.
>
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | The major speedup in any append operation is to use the free space of the current block without requesting more space from the GC.
To determine if the new data can fit in the current block, one needs to get the current block size. With builtin arrays, this is a lookup of both the block info for the current block (which either is in the LRU cache or is obtained by searching the heap metadata), and then a look inside the hidden 'allocated' length element inside the memory block. When the cache is used, this is not a complexity-wise expensive operation (it should be a constant), but it's a rather large constant. You must call several functions, do a search through the cache, figure out where your 'allocated' length is stored in the block, etc.
With Appender, the capacity is stored with the instance, so instead of all these lookups in the GC/cache etc, it's just a pointer dereference. Plus, since we assume the appender owns the data, it is assumed we can always append. So the constant factor is drastically smaller (a couple instructions), and guaranteed bounded, does not have any interaction with other threads (no GC lock to take).
I think Appender should be as fast as possible when appending data, since that is what it's supposed to be good at. I don't see a point of simply wrapping builtin array appending, what's so bad about the builtin syntax that you need to define a wrapper around it?
-Steve
----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Thu, November 18, 2010 4:42:02 PM
> Subject: Re: [phobos] Clear appending cache?
>
> What is the efficiency difference? Can it be reduced?
>
> Andrei
>
> On 11/18/10 1:36 PM, Steve Schveighoffer wrote:
> > Appender is currently much faster than array appending because it has a dedicated place to store the array length/capacity. Simply wrapping arrays makes it much slower (which has a necessarily very convoluted way to lookup
>the
> > block capacity). Or am I missing something?
> >
> > -Steve
> >
> >
> >
> > ----- Original Message ----
> >> From: Andrei Alexandrescu<andrei at erdani.com>
> >> To: Discuss the phobos library for D<phobos at puremagic.com>
> >> Sent: Thu, November 18, 2010 4:28:43 PM
> >> Subject: Re: [phobos] Clear appending cache?
> >>
> >> Related question: can we make Appender a thin wrapper over arrays? It looks like improving "~=" caching is the right way to place effort.
> >>
> >> Andrei
> >>
> >> On 11/18/10 1:15 PM, David Simcha wrote:
> >>> Can someone who knows better than me how it works (probably Steve)
> >>> please put a function in druntime to clear the current thread's array
> >>> appending cache? I need this for two reasons:
> >>>
> >>> 1. To make sure arrays I'm done with get GC'd.
> >>>
> >>> 2. To make it safe(r) to free arrays manually.
> >>>
> >>>
> >>>
> >>> _______________________________________________
> >>> phobos mailing list
> >>> phobos at puremagic.com
> >>> http://lists.puremagic.com/mailman/listinfo/phobos
> >> _______________________________________________
> >> phobos mailing list
> >> phobos at puremagic.com
> >> http://lists.puremagic.com/mailman/listinfo/phobos
> >>
> >
> >
> >
> > _______________________________________________
> > phobos mailing list
> > phobos at puremagic.com
> > http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
|
November 18, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Schveighoffer | On 11/18/10 2:15 PM, Steve Schveighoffer wrote:
> I think Appender should be as fast as possible when appending data, since that is what it's supposed to be good at. I don't see a point of simply wrapping builtin array appending, what's so bad about the builtin syntax that you need to define a wrapper around it?
On the contrary, I want to make Appender as unnecessary as possible, and ~= as efficient as possible without requiring the use of Appender.
Andrei
|
November 19, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | ----- Original Message ---- > From: Andrei Alexandrescu <andrei at erdani.com> > On the contrary, I want to make Appender as unnecessary as possible, and ~= as >efficient as possible without requiring the use of Appender. An array is 2 fields, length and pointer. There is no room for another field, so the lookup of the block size and embedded length is necessarily complex and time consuming. Not only that, but an array may not be the owner of its data. The lookup must answer two questions: 1. Is there enough room in the block I can extend into? 2. If I extend, will I overwrite data that is being used elsewhere? Without more fields in the array type, I don't see how it's possible to make it as fast as Appender, and I very much do not want to try and add more fields to an array, 2 words is a perfect size. Do you have any ideas on how it can be faster? -Steve |
November 19, 2010 [phobos] Clear appending cache? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Schveighoffer | Steve, Andrei, an idea: Give Appender array operators like ~= and []. That way you can think about it as an enhanced array, an append-friendly array, and not just as an odd struct with a stream-like interface. |
Copyright © 1999-2021 by the D Language Foundation