{"id":35141478,"url":"https://github.com/freref/spsc-queue","last_synced_at":"2026-05-20T17:05:36.456Z","repository":{"id":313564782,"uuid":"1051861795","full_name":"freref/spsc-queue","owner":"freref","description":" Fast bounded SPSC queue written in Zig","archived":false,"fork":false,"pushed_at":"2025-09-08T21:32:54.000Z","size":38,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-30T18:54:07.130Z","etag":null,"topics":["spsc-queue","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/freref.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-06T21:56:23.000Z","updated_at":"2025-12-15T19:56:09.000Z","dependencies_parsed_at":"2025-09-07T00:07:38.161Z","dependency_job_id":"9737a86b-c175-419a-835c-b5eaf1452d58","html_url":"https://github.com/freref/spsc-queue","commit_stats":null,"previous_names":["freref/spsc-queue"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/freref/spsc-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freref%2Fspsc-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freref%2Fspsc-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freref%2Fspsc-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freref%2Fspsc-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freref","download_url":"https://codeload.github.com/freref/spsc-queue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freref%2Fspsc-queue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33268329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-20T15:12:43.734Z","status":"ssl_error","status_checked_at":"2026-05-20T15:12:42.300Z","response_time":356,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["spsc-queue","zig","zig-package"],"created_at":"2025-12-28T11:33:38.910Z","updated_at":"2026-05-20T17:05:36.450Z","avatar_url":"https://github.com/freref.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spsc-queue\nA single producer single consumer wait-free and lock-free fixed size queue written in Zig. Inspired by [rigtorp's](https://github.com/rigtorp/SPSCQueue/tree/master) implementation in C++. This implementation is faster than [rigtorp/SPSCQueue](https://github.com/rigtorp/SPSCQueue/tree/master),\n[*boost::lockfree::spsc*](https://www.boost.org/doc/libs/1_76_0/doc/html/boost/lockfree/spsc_queue.html), [cdolan/zig-spsc-ring](https://github.com/cdolan/zig-spsc-ring.git), and [*folly::ProducerConsumerQueue*](https://github.com/facebook/folly/blob/master/folly/docs/ProducerConsumerQueue.md).\n\n## Implementation\nThis library provides a **managed** and an **unmanaged** version of the queue, following the Zig standard library conventions. There are **2 implementations** of the queue:\n- One that uses a slack space in the buffer and allows the user to set any capacity.\n- One that enforces power-of-2 (po2) capacity and is faster due to less expensive arithmetic operations.\n\nThe user can choose which implementation they want to use by setting the ``enforce_po2`` flag to ``true`` when defining the queue type. I opted for this interface over detecting if the capacity is po2, because the flag makes the choice explicit and known at comptime. It's clear to the user that there are two distinct implementations with different trade-offs. I borrowed this idea from [joadnacer/atomic_queue](https://github.com/joadnacer/atomic_queues.git).\n\n## Usage\nYou can find a basic example [here](./src/example.zig). You can run this example with the following command:\n```sh\nzig build run-example\n```\n\n**Unmanaged version:**\n```zig\npub fn initBuffer(buffer: []T) Self\npub fn initCapacity(allocator: std.mem.Allocator, num: usize) !Self\npub fn deinit(self: *Self, allocator: std.mem.Allocator) void\n```\n\n**Managed version:**\n```zig\npub fn initCapacity(allocator: std.mem.Allocator, num: usize) !Self\npub fn fromOwnedSlice(allocator: std.mem.Allocator, buffer: []T) Self\npub fn deinit(self: *Self) void\n```\n\n**General API:**\n```zig\npub fn isEmpty(self: *Self) bool\npub fn size(self: *Self) usize\npub fn push(self: *Self, value: T) void\npub fn tryPush(self: *Self, value: T) bool\npub fn front(self: *Self) ?*T\npub fn pop(self: *Self) void\n```\n\n## Benchmarks\nI made a seperate repo for benchmarking various SPSC queue implementations, more info on the benchmarks can be found [there](https://github.com/freref/spsc-queue-benchmark/tree/master). These benchmarks are currently not very rigorous, but they give a rudimentary idea of the performance of this implementation compared to others. The benchmarks were run on a MacBook Pro (Apple M4 Pro, 14 cores: 10 performance + 4 efficiency) with 48 GB unified memory. ![Benchmarks bar chart](https://github.com/freref/spsc-queue-benchmark/blob/master/benchmarks.png?raw=true)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreref%2Fspsc-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreref%2Fspsc-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreref%2Fspsc-queue/lists"}