4 ms·
You don't have to use a channel for coordination. Here is a lexer implementation (in C!) that very closely follows Rob Pike's talk and uses a ring buffer for co
by alex_smart 4y ago
You don't have to use a channel for coordination. Here is a lexer implementation (in C!) that very closely follows Rob Pike's talk and uses a ring buffer for coordination and is plenty fast.
https://github.com/lpereira/lwan/blob/master/src/lib/lwan-template.c https://github.com/lpereira/lwan/blob/master/src/lib/lwan-te...
If you watch the talk carefully, Rob Pike himself mentions this near the end of the talk.
- jchw 4y agoEven if you do this, the CPU still ultimately has to synchronize if you put the workflow across threads, so you have to get a contention hit somewhere. (Lockfree data structures still hit locks in the silicon, after all.) I could be wrong, but when it comes to performance it seems like your best option is moving the concurrency elsewhere. For design? I dunno. I find the design to be elegant for sure, but I also don’t mind handwriting parsers in general.
- alex_smart 4y agoThe lexer is entirely single-threaded, as in the original Rob Pike talk. >I find the design to be elegant for sure, but I also don’t mind handwriting parsers in general. But this is a hand-written parser! Just using function pointers to store the state instead of using an enum and switch statements.
- jchw 4y agoYep, fair enough. As a single-threaded design, I have no particular problems with it.