[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: thoughts on ports
Re: thoughts on ports
Thu, 17 Jan 2013 15:40:33 +0100
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)
Again, picking up old things:
On Wed 11 Apr 2012 00:11, address@hidden (Ludovic Courtès) writes:
> Andy Wingo <address@hidden> skribis:
>> Obviously we need ports implemented in C because of bootstrapping
>> concerns. But can we give Scheme access to buffering and the underlying
>> fill (read) / drain (write) / wait (select) operations?
>> So, the idea: refactor the port buffers (read, write, putback) to be
>> Scheme bytevectors, and internally store offsets instead of pointers.
>> Give access to some internal port primitives to a new (ice-9 ports)
>> I think we can manage to make (ice-9 ports) operate in both binary and
>> textual modes without a problem, just as we do with cports. We'll have
>> to expose some iconv primitives to (ice-9 ports), but that's just as
>> well. (Perhaps we should supply an (ice-9 iconv) module ?)
> I like the idea (more Scheme!). However, it’s not clear to me what the
> performance impact would be with Guile’s current state.
> For instance, while ‘read’ remains in C, it can only suffer from such a
> change. Conversely, things like ‘get-u8’ and ‘get-bytevector-n!’ may be
> faster. OTOH, the equivalent of ‘get_utf8_codepoint’ is likely to be
> much slower. And we still need to call out to C for ‘iconv’ and
As a thought experiment, I don't see why things should have to slow
down. Master has `scm_c_take_gc_bytevector', which can be used to wrap
the existing scm_t_port::write_buf, ::read_buf, and ::putback_buf
members. At the cost of three allocations per port and three words per
allocation (bytevector tag, length, and pointer), we could give access
to these internal buffers to Scheme without affecting the C code at all.
We could go farther and allocate the buffers as bytevectors directly,
which would entail an additional indirection for C to get at the length
and data, but the length and data would all be contiguous anyway so in
practice I don't see it being too bad.
I'll see what I can do in a branch.
- Re: thoughts on ports,
Andy Wingo <=