Making My Debug Build 100x Faster: SIMD and Dedicated Silicon to the Rescue

2025-02-18

While developing a C-based torrent application, the author encountered a slow debug build startup time (20-30 seconds). This was mainly due to the program's startup verification of SHA1 hash values for each downloaded file piece, significantly slowed by Address Sanitizer in debug mode. The article explores several optimization techniques, including using SIMD instructions and the CPU's dedicated SHA acceleration hardware. Ultimately, using Intel's SHA extension instruction set reduced startup time to 866.9 milliseconds, achieving a 100x performance improvement. The article details the implementation and performance comparison of various optimization approaches, discussing compiler optimization and the impact of disk I/O.

Read more
Development

The Elusive Cross-Platform Timer API: A Journey Through OS APIs

2025-02-06

This article explores the challenges of cross-platform timer APIs in C programming. The author discovers that different Unix systems (including Linux, FreeBSD, NetBSD, etc.) handle timers very differently. The POSIX timer_create function, based on signals, presents numerous problems, such as poor interoperability with other OS primitives and signal mask interference. The article delves into the pros and cons of various solutions, including timerfd_create, kqueue, port_create, and io_uring, ultimately concluding that for cross-platform applications, implementing timers in userspace, as libuv does, is a more efficient and reliable approach. Libuv uses a min-heap data structure to manage timers and uses system calls like poll/epoll/kqueue for multiplexing.

Read more