develooper Front page | perl.perl6.language | Postings from September 2005

Re: Lazy lists and optimizing for responsiveness

Thread Previous
From:
Yuval Kogman
Date:
September 21, 2005 00:25
Subject:
Re: Lazy lists and optimizing for responsiveness
Message ID:
20050921072440.GH5797@woobling.org
On Tue, Sep 20, 2005 at 14:47:33 -0400, Austin Frank wrote:
> Would the named adverbs for gather work in other contexts as well?
> Would you suggest this mechanism for specifying the buffering
> behavior for IO operations?

See scook's email below... I think that yes. Here is a reference
implementation making heavy use of coros:

	sub buffer_lazy (*@lazy, +$threshold = 100) { # renamed scook's force_async
		my @buffer;

		state Sem $collecting;

		if (!@buffer) { # blocking
			push @buffer, shift @lazy;
		}

		if (@buffer.elems < $threshold and $collecting.lock(:nonblocking)) {
			async {
				LEAVE { $colecting.release };

				while (@buffer.elems < $threshold) {
					push @buffer , shift @lazy; # or splice it splice returns a lazy list
				}
			}
		}
		
		yield shift @buffer;
	}

	my @lazy = buffer_lazy @other_lazy; # using @lazy should be more responsive

and where gather is

	sub gather (&body, +$async, +$threshold){
		my @result_list = {
			temp sub *take (*@stuff) {
				&OUTER::yield(@stuff); # how do we do this? Maybe $?CALLER_CONTINUATION.yield?
			}
			body();
		};
	
		return $async
			?? buffer_lazy @result_list :threshold($threshold)
			!! @result_list;
	}

> Tim Bray recently wrote about wanting a language that would be
> smarter about IO buffering by default.  Will perl6 be such a
> language?

I think it already is about making life easy for the programmer. For
example, the 'will prompt' trait gives autoprompting to a read
handle, by making each read go to another handle, print, flush it
smartly for interactivity, and then actually read the data. This
makes the programmer's life less painful in many ways by
encapsulating a common problem in a standard library definition.

As for Tim's problem, I don't know what exactly Tim means, since I
don't know what he fixed in his program, but "I/O primitives are by
default bufferred unless the programmer specifically requested
otherwise" sounds a lot like perl 5 and $| ;-)

I think that Perl 6 needs more than this to be "smarter about IO
buffering", but I'm not sure I want it to be.


-- 
 ()  Yuval Kogman <nothingmuch@woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me beats up some cheese: neeyah!!!!!!!!!!!!!!!!!


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About