On Fri, Oct 26, 2012 at 4:51 PM, Russ P. <russ.p...@gmail.com> wrote:
> In one of Martin's coursera lectures for this week, he discusses appending
> an element to a Vector. Please correct me if I am wrong, but that does not
> appear to be an efficient operation that one would want to do many times to
> build a Vector. Also, the resulting Vector does not appear to have the same
> form as one would expect. Did I understand correctly that simply appending a
> single element always adds an array of length 32? I hope not!
>
> A while back I discovered and started using a class called VectorBuilder,
> which I assume is a more efficient way to build a Vector. Perhaps Martin
> should have mentioned it in his lecture.
It does create at least one array of length 32, and possibly up to 6,
as would any update operation. But, here's the kick: because of the
bad locality of common lists, creating an array of 32 elements and
creating a single cons have about the same cost compared to the cache
miss. The vector then gains performance back because of locality of
reference on reads.
Trust me, both finalizers and WeakReferences are things you want to avoid if you want performance.
On Sun, Oct 28, 2012 at 6:01 PM, Rex Kerr <ich...@gmail.com> wrote:
You reference "count" the linear extension only. Any branching (i.e. two child vectors with the same parent) causes duplication as now. No cycles.
Sorry, I mean you won't have any _extra_ worry about cycles due to the reference-counting scheme. The GC (and programmer) of course have to worry about cycles.
Viktor: WeakReference doesn't look that bad in my limited use and limited benchmarking. It's a wrapper, so yes, there's a cost to having an extra wrapper. Otherwise, it doesn't seem to be worse than any other indirection, whereas finalize makes GC take considerably longer (~3-4x in my unrealistic benchmarks).
On Sun, Oct 28, 2012 at 6:31 PM, Rex Kerr <ich...@gmail.com> wrote:Sorry, I mean you won't have any _extra_ worry about cycles due to the reference-counting scheme. The GC (and programmer) of course have to worry about cycles.
Viktor: WeakReference doesn't look that bad in my limited use and limited benchmarking. It's a wrapper, so yes, there's a cost to having an extra wrapper. Otherwise, it doesn't seem to be worse than any other indirection, whereas finalize makes GC take considerably longer (~3-4x in my unrealistic benchmarks).Perhaps I have different performance needs from most other people. :-)Cheers,√
--Rex