(Untitled)

Jun 02, 2008 12:09

Random thought: I'm sure people who actually know about this stuff will be able to tell me why it won't work, or, alternatively, cases where it's already been done.

Recall the problem with the naive Haskell mean program
mean xs = sum xs / length xs
which when asked to calculate the mean of [1 .. 1e9] allocates 8GB of RAM and brings the computer to a ( Read more... )

computers, programming, beware the geek, ruby, haskell

Leave a comment

Comments 12

thesz June 2 2008, 12:11:44 UTC
Any (finite) Smart VM is strictly less powerful than infinite amount of programmer's... abilities. ;)

But, there were talks about forcing thunks on garbage collector stage, it should improve memory behavior.

Reply

pozorvlak June 2 2008, 12:15:33 UTC
Any (finite) Smart VM is strictly less powerful than infinite amount of programmer's... abilities. ;)

Sure, but there are only finitely many programmers, each of whom have a finite amount of time in which to perform optimisations :-) And Yegge's point (which is borne out in practice) is that VMs have access to accurate runtime data for the program as it is actually being used, and so are in a position to make better decisions about optimisation than the programmer was at compile-time.

Reply

retort thesz June 2 2008, 13:01:45 UTC
Again, the number of programmers making VM to be in position to make better decision about optimization is O(log N), where N is a total number of programmers.

And log N is a constant already around N=106. ;)

Reply


figg June 2 2008, 13:22:27 UTC
The less naive version of mean avoids this problem by calculating the sum and length in parallel.

Instead of trying to do clever things we don't know how to do, would it be possible to do an automatic transform to turn the naive version into the parallel version?

Reply

pozorvlak June 2 2008, 14:24:50 UTC
I asked about this: apparently with the current GHC optimization setup, the rule
{-# RULES "foldl fusion"
forall f g h z1 z2 xs . f (foldl g z1 xs) (foldl h z2 xs) =
(uncurry f) (foldl (\(a,b) x -> (g a x, g b x)) (z1, z2) xs)
#-} isn't allowed, because it's the application of a variable - rules are indexed on the function that's applied at the head. So, in principle yes, but not with GHC as it currently stands.

And, while looking for that, I discovered that someone else had already had the idea of this post - or rather, someone else had the first half, and I chipped in with the second half two weeks ago, and then forgot about it :-(

Reply

figg June 2 2008, 14:59:48 UTC
I thought you'd seen that post.

I still don't think that making the GC throw away data is the right way to approach this problem, when the essence of it is evaluating inherently parallel functions in serial on a very long list.

It's a little annoying that you can't do it with the existing GHC setup, but I'm still new to haskell myself - I imagine though it might be possible to do the same with more ugly rules though.

Reply

pozorvlak June 2 2008, 15:40:33 UTC
I had seen that post - the third comment in that thread is mine :-) I'd forgotten about the connection to optimising VMs until I thought of it again yesterday, which is why I wrote this post.

Reply


necaris June 2 2008, 13:46:29 UTC
I think PyPy might do something like this -- they certainly do have a runtime profiling-and-optimizing chunk of their VM with hooks into everything from garbage collection to JIT...

Reply

pozorvlak June 2 2008, 14:25:33 UTC
PyPy sounds like a pretty cool project in general. Thanks!

Reply

figg June 2 2008, 17:44:30 UTC
Since this is a link dump thread of conversation ( ... )

Reply


[BUY] Super Cheap SEO VPS - Earn more online anonymous February 19 2011, 03:43:43 UTC
Hey there,

Are you into doing Seo work or perhaps spamming weblogs? Well i can offer you a very cheap VPS with the following software installed (You use my license!)

SENuke pro edition (Normally costs $127 monthly)
Scrapebox ($97)
The Best Spinner ($77 yearly)

Watch my quick YouTube video! http://www.youtube.com/watch?v=paExU60Hy8A

You can aquire usage of all three of those ultra powerful SEO tools for a small charge of $50 monthly.

The VPS server itself is extremely powerful and fast, you simply will not find this sort of offer anywhere else for this sort of price!

Visit http://hellomotow.net For more information

Reply


Leave a comment

Up