{"id":16831195,"url":"https://github.com/zbjornson/fast-hex","last_synced_at":"2025-03-22T04:30:37.830Z","repository":{"id":51701684,"uuid":"103100845","full_name":"zbjornson/fast-hex","owner":"zbjornson","description":"Fast, SIMD hex string encoder and decoder C++ lib and Node.js module","archived":false,"fork":false,"pushed_at":"2022-09-19T21:23:06.000Z","size":36,"stargazers_count":58,"open_issues_count":1,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-18T08:11:14.446Z","etag":null,"topics":["avx","avx2","buffers","hex","hexadecimal","nodejs","simd","strings"],"latest_commit_sha":null,"homepage":"","language":"C++","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/zbjornson.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}},"created_at":"2017-09-11T06:57:46.000Z","updated_at":"2025-02-03T14:21:29.000Z","dependencies_parsed_at":"2023-01-18T14:45:25.486Z","dependency_job_id":null,"html_url":"https://github.com/zbjornson/fast-hex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbjornson%2Ffast-hex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbjornson%2Ffast-hex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbjornson%2Ffast-hex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbjornson%2Ffast-hex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbjornson","download_url":"https://codeload.github.com/zbjornson/fast-hex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244907420,"owners_count":20529850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["avx","avx2","buffers","hex","hexadecimal","nodejs","simd","strings"],"created_at":"2024-10-13T11:42:39.267Z","updated_at":"2025-03-22T04:30:37.395Z","avatar_url":"https://github.com/zbjornson.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fast Hex\n\nA fast, SIMD (vectorized) hex string encoder/decoder, available as a stand-alone\nC++ module and as a Node.js module.\n\n* Supports upper-case and lower-case characters.\n* Does not validate input. (I'm open to a PR to add this as an option.)\n* Requires AVX2 (Haswell or later).\n\nI think these implementations are close to optimal, but PRs are welcome for\noptimizations.\n\n---\n\n## C++\n\nPull in `src/hex.h` and `src/hex.cc`, and adjust your build appropriately\n(GCC/Clang/ICC: `-march=haswell` for example; MSVC: set\n`EnableAdvancedInstructionSet` to \"AVX2\" or `/arch:AVX2`).\n\nSee `hex.h` for the exported functions. There are three decoder implementations\nand two encoder implementations, with the same signature:\n\n```cpp\n// Decodes src hex string into dest bytes.\n// len is number of dest bytes (1/2 the size of src).\nvoid decodeHex___(uint8_t* __restrict__ dest, const uint8_t* __restrict__ src, size_t len);\n\n// Encodes src bytes into dest hex string.\n// len is number of src bytes (dest must be twice the size of src).\nvoid encodeHex___(uint8_t* __restrict__ dest, const uint8_t* __restrict__ src, size_t len);\n```\n\n**Benchmark**\n* Decoding ~12.5x over scalar.\n* Encoding ~11.5x over scalar.\n\n---\n\n## Node.js\n\n```typescript\nconst {decodeHexVec, encodeHexVec} = require(\"fast-hex\");\ndecodeHexVec(output: Uint8Array|Buffer, input: Uint8Array|Buffer): void;\nencodeHexVec(input: Uint8Array|Buffer): string;\n```\n\n**Benchmark**\n* ~2.12x faster decoding for short string inputs (\u003c 1,031,913 chars).\n* ~12x faster decoding for some long strings, Buffers and TypedArrays.\n* ~5.5x faster encoding.\n\nDevelopment notes:\n* Accessing string bytes from v8 is slow. Node uses external strings in some\n  cases, but so far the only scenarios in which I've found them used are (a)\n  via `buffer.toString()`, (b) via the C++ API\n  `v8::Local\u003cv8::Value\u003e node::Encode(v8::Isolate* isolate, const char* buf, size_t len, enum encoding encoding)`.\n  Haven't looked yet at what cases cause v8 to automatically use external\n  strings.\n* `stream.write` uses `StringBytes::Encode` internally. Can't replace this\n  without modifying node.js, unless we intercept `stream.write` in JS.\n* Creating strings is also expensive. Still need to look at if there's a better\n  way to do this, and definitely need to use external strings over some length threshold.\n\n---\n\nSupported compilers:\n* MSVC 2015 or later, or Visual C++ Build Tools 2015 or later\n* Clang 3.4.x or later\n* GCC 4.8.x or later\n* ICC 16 or later\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbjornson%2Ffast-hex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbjornson%2Ffast-hex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbjornson%2Ffast-hex/lists"}