You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **⚠️ Experimental Project**: This is a showcase project for Go 1.26's experimental `simd/archsimd` package. The SIMD API is unstable and may change in future Go releases. Not recommended for production use.
A high-performance CSV parser for Go using SIMD (Single Instruction Multiple Data) instructions. Drop-in replacement for the standard library's `encoding/csv` package with performance improvements on AMD64 processors with AVX-512 support.
6
8
7
-
## Features
9
+
SIMD-accelerated CSV parser for Go - Drop-in replacement for `encoding/csv` with AVX-512 optimization.
8
10
9
-
-**SIMD-accelerated parsing**: Uses Go 1.26's experimental `simd/archsimd` package with 256-bit vectors (requires AVX-512BW for `ToBits()` operation)
10
-
-**API compatible**: Drop-in replacement for `encoding/csv.Reader` and `encoding/csv.Writer`
11
-
-**RFC 4180 compliant**: Full support for quoted fields, escaped quotes, multiline fields, and CRLF normalization
12
-
-**Automatic fallback**: Gracefully falls back to scalar implementation on CPUs without AVX-512
13
-
-**Zero-copy API**: `ParseBytes` function for direct byte slice parsing without io.Reader overhead
11
+
> **Experimental**: Requires Go 1.26+ with `GOEXPERIMENT=simd`. The SIMD API is unstable and may change now. Not recommended for production use.
14
12
15
-
## Requirements
13
+
## Quick Start
14
+
15
+
```go
16
+
import csv "github.com/nnnkkk7/go-simdcsv"
16
17
17
-
-**Go 1.26+** with `GOEXPERIMENT=simd` build tag (experimental)
18
-
-**AMD64 architecture** (x86-64) only
19
-
-**AVX-512 support** for SIMD acceleration (AVX512F, AVX512BW, AVX512VL required)
Same API as `encoding/csv` - just change the import.
22
24
23
-
-**Experimental SIMD API**: The `simd/archsimd` package is experimental and AMD64-specific. A portable high-level SIMD package is planned for future Go releases.
24
-
-**AVX-512 dependency**: Despite using 256-bit vectors (`Int8x32`), the `ToBits()` method requires AVX-512BW instruction (VPMOVB2M). This means SIMD acceleration is **not available** on:
25
-
- Most CI environments (GitHub Actions `ubuntu-latest`, etc.)
26
-
- CPUs without AVX-512 (Intel before Skylake-X, most AMD before Zen 4)
27
-
- Apple Silicon (ARM64)
28
-
-**Memory**: Currently reads entire input into memory (streaming I/O planned)
25
+
## Features
29
26
30
-
> **Note**: On unsupported CPUs, the library automatically falls back to a scalar implementation with no SIMD acceleration.
27
+
| Feature | Description |
28
+
|---------|-------------|
29
+
|**API Compatible**| Drop-in replacement for `encoding/csv.Reader` and `Writer`|
1.**`scanBuffer()`**: Scans input in 64-byte chunks using 256-bit SIMD vectors (`archsimd.Int8x32`). Detects positions of structural characters (`"`, `,`, `\n`, `\r`) and outputs bitmasks. Handles CRLF normalization and tracks quote state across chunk boundaries.
120
+
| Stage | Function | Description |
121
+
|-------|----------|-------------|
122
+
|**Scan**|`scanBuffer()`| SIMD scanning in 64-byte chunks. Detects `"`, `,`, `\n`, `\r` positions as bitmasks. Handles CRLF and quote state across boundaries. |
123
+
|**Parse**|`parseBuffer()`| Iterates bitmasks to find field boundaries. Outputs `fieldInfo` (offset, length) and `rowInfo` (field count). |
2.**`parseBuffer()`**: Iterates through bitmasks to determine field boundaries. Outputs `fieldInfo` (start offset, length) and `rowInfo` (field count per row). Correctly handles quoted fields containing commas or newlines.
3.**`buildRecords()`**: Extracts strings from byte positions. Applies double-quote unescaping (`""` → `"`) for fields that were marked during scanning.
134
+
### Without AVX-512
181
135
182
-
## Building and Testing
136
+
The library **still works** but falls back to scalar implementation (no speedup). This includes:
137
+
- Most CI environments (GitHub Actions `ubuntu-latest`, etc.)
138
+
- Intel CPUs before Skylake-X
139
+
- AMD CPUs before Zen 4
140
+
- Apple Silicon (ARM64)
183
141
184
-
### AMD64 Environment
142
+
##Building & Testing
185
143
186
144
```bash
187
-
# Build with SIMD support
145
+
# Build
188
146
GOEXPERIMENT=simd go build ./...
189
147
190
-
#Run tests
148
+
#Test
191
149
GOEXPERIMENT=simd go test -v ./...
192
150
193
-
#Run benchmarks
151
+
#Benchmark
194
152
GOEXPERIMENT=simd go test -bench=. -benchmem
195
153
```
196
154
197
155
## Performance
198
156
199
-
Benchmarks comparing `go-simdcsv` against `encoding/csv` (run on AMD64 with AVX-512):
157
+
Benchmarks comparing `go-simdcsv` against `encoding/csv`:
> TODO: Add benchmark results from AVX-512 environment.
166
+
167
+
## Known Limitations
168
+
169
+
-**Experimental API**: `simd/archsimd` may have breaking changes in future Go releases
170
+
-**Memory**: Reads entire input into memory (streaming I/O planned for future)
171
+
-**Custom delimiters**: Some edge cases with non-comma delimiters may differ from `encoding/csv`
202
172
203
173
## Contributing
204
174
@@ -207,9 +177,3 @@ Contributions are welcome! Please open issues or pull requests on GitHub.
207
177
## License
208
178
209
179
MIT License - see [LICENSE](LICENSE) file for details.
210
-
211
-
## Known Issues
212
-
213
-
-**CI environments**: Most CI runners (GitHub Actions, etc.) do not have AVX-512 support. Tests pass using the scalar fallback, but SIMD acceleration is not tested in CI.
214
-
-**Apple Silicon**: Not supported. This library is AMD64-specific.
215
-
-**Go SIMD API stability**: The `simd/archsimd` package is experimental. Future Go releases may introduce breaking changes.
0 commit comments