4 ms·
Is there a reason why you’re not using libdispatch on darwin and instead using kqueue directly?
by williamcotton 4y ago
Is there a reason why you’re not using libdispatch on darwin and instead using kqueue directly?
- jorangreef 4y agoAt the time, we wanted to get macOS or Darwin running as soon as possible to improve the local developer experience, but—we've always had a soft spot for FreeBSD so kqueue was two birds in one!
- kprotty 4y agoKing from TigerBeetle here. One of the reasons is that libdispatch's I/O functions introduce extra dynamic allocations for internal queueing via `dispatch_async` ([0],[1],[2]) and from an API perspective of realloc-ing [3] an internally owned [4] buffer. TigerBeetle, on the other hand, statically allocates all I/O buffers upfront [5], treats these buffers as intrusively-provided typed data [6] (no growing/owned buffers), and does internal queueing without synchronization or dynamic allocation [7]. [0]: https://github.com/apple/swift-corelibs-libdispatch/blob/469c8ecfa0011f5da23acacf8658b6a60a899a78/src/queue.c#L889 https://github.com/apple/swift-corelibs-libdispatch/blob/469... [1]: https://github.com/apple/swift-corelibs-libdispatch/blob/469c8ecfa0011f5da23acacf8658b6a60a899a78/src/io.c#L847-L860 https://github.com/apple/swift-corelibs-libdispatch/blob/469... [2]: https://github.com/apple/swift-corelibs-libdispatch/blob/469c8ecfa0011f5da23acacf8658b6a60a899a78/src/io.c#L1178-L1190 https://github.com/apple/swift-corelibs-libdispatch/blob/469... [3]: https://github.com/apple/swift-corelibs-libdispatch/blob/469c8ecfa0011f5da23acacf8658b6a60a899a78/src/io.c#L2325-L2361 https://github.com/apple/swift-corelibs-libdispatch/blob/469... [4]: https://developer.apple.com/documentation/dispatch/1388933-dispatch_read https://developer.apple.com/documentation/dispatch/1388933-d... [5]: https://tigerbeetle.com/blog/a-database-without-dynamic-memory/ https://tigerbeetle.com/blog/a-database-without-dynamic-memo... [6]: https://github.com/tigerbeetledb/tigerbeetle/blob/d15acc663f8882cb02413129e8351bf3238335e6/src/message_bus.zig#L676-L685 https://github.com/tigerbeetledb/tigerbeetle/blob/d15acc663f... [7]: https://github.com/tigerbeetledb/tigerbeetle/d15acc663f8882cb02413129e8351bf3238335e6/main/src/io/darwin.zig#L16-L18 https://github.com/tigerbeetledb/tigerbeetle/d15acc663f8882c...
- williamcotton 4y agoThank you! I was indeed looking for the technical details!