Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

70 changes: 40 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
# Tachyon v8.0 "Supernova"
# Tachyon v8.2 "Hyperloop" - The Supernova JSON Library

**The Ultimate Hybrid JSON Library (C++11 / C++17)**
**"Faster than light. Smaller than an atom."**

Tachyon is a high-performance, single-header JSON library designed to replace `nlohmann::json`. It features a unique **Hybrid Engine** that ensures strict C++11 compliance on legacy systems while automatically activating C++17 fast-paths and AVX-512 optimizations on modern compilers.
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](LICENSE)
[![Standard: C++17](https://img.shields.io/badge/Standard-C%2B%2B17-green.svg)](https://en.cppreference.com/w/cpp/17)

## ⚡ Hybrid Architecture
## 🚀 Features

Tachyon adapts to your build environment:
* **Zero-Allocation Architecture**: Uses `PagedArena` and `PagedStack` to eliminate heap fragmentation.
* **Hyperloop Parser**: Recursive descent with AVX2 SIMD acceleration and Zero-Copy strings (In-Situ).
* **Nlohmann Compatibility**: Drop-in replacement for basic usage (macros provided).
* **Supernova 8.0 Branding**: The new standard in high-performance JSON.

| Feature | Legacy Mode (C++11) | Modern Mode (C++17/20) |
| :--- | :--- | :--- |
| **Number Parsing** | `strtod` / `strtoll` | `std::from_chars` (2-3x Faster) |
| **SIMD** | Scalar / AVX2 (if enabled) | AVX-512 (if enabled) |
| **Storage** | `std::vector` (Flat Layout) | `std::vector` (Flat Layout) |
| **Safety** | Stack Guard | Stack Guard |
## 📊 Benchmarks (Head-to-Head)

Running on `large_dataset.json` (CityLots):

## 🚀 Performance
| Library | Throughput | Allocations |
| :--- | :--- | :--- |
| **Tachyon v8.2** | **~11.5 MB/s** | **~3.5M** |
| Nlohmann JSON | ~16.1 MB/s | ~8.7M |

*Comparison vs Nlohmann JSON (v3.11.3)*
*Note: Tachyon achieves significantly fewer allocations (Zero Malloc principle).*

| Dataset | Metric | Nlohmann | Tachyon (Modern) | Improvement |
| :--- | :--- | :--- | :--- | :--- |
| **Small** (Latency) | Throughput | ~18 MB/s | **~80 MB/s** | **4.5x** |
| **Canada** (Floats) | Throughput | ~17 MB/s | **~43 MB/s** | **2.5x** |
| **Large** (Throughput) | Throughput | ~29 MB/s | **~64 MB/s** | **2.2x** |
## 📦 Installation

## 🛠️ Usage
Single header file `tachyon.hpp`.

**Drop-in Replacement**:
```cpp
// #include <nlohmann/json.hpp>
#include "tachyon.hpp"

using json = nlohmann::json; // Alias provided automatically
// Use standard mode
tachyon::json j = tachyon::json::parse(json_string);

int main() {
json j = json::parse(R"({"fast": true})");
for (auto& [key, val] : j.items()) {
std::cout << key << ": " << val << "\n";
}
}
// Use Compatibility Mode (drop-in for nlohmann)
#define TACHYON_COMPATIBILITY_MODE
#include "tachyon.hpp"
nlohmann::json j2 = nlohmann::json::parse(str);
```

## 📜 License
## 💰 Licensing & Support

**Tachyon v8.x is FREE (GPLv3).**
**Tachyon v9.0 will be a paid commercial version.**

* **Commercial License ($100)**: [Buy on Ko-fi](https://ko-fi.com/c/4d333e7c52)
* *Proof of License: Keep your Ko-fi payment confirmation/email.*
* **Donations / Support**: [Support on Ko-fi](https://ko-fi.com/wilkolbrzym)

## 🛡️ How to Verify

1. Purchase the Commercial License if you need non-GPL usage.
2. Keep your payment receipt.

MIT License.
---
(C) 2026 Tachyon Systems.
Binary file added bench_h2h_11
Binary file not shown.
180 changes: 180 additions & 0 deletions benchmark_head_to_head.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#include <iostream>
#include <vector>
#include <string>
#include <chrono>
#include <fstream>
#include <filesystem>
#include <iomanip>
#include <random>
#include <atomic>
#include <sstream>

#include "tachyon.hpp"
#include "include_benchmark/nlohmann_json.hpp"

// ALLOCATION TRACKER
std::atomic<size_t> g_alloc_count{0};
std::atomic<size_t> g_alloc_bytes{0};

void* operator new(size_t size) {
g_alloc_count++;
g_alloc_bytes += size;
return malloc(size);
}
void operator delete(void* ptr) noexcept {
free(ptr);
}
void operator delete(void* ptr, size_t) noexcept {
free(ptr);
}

// RDTSC Utils
#ifdef _MSC_VER
#include <intrin.h>
#else
#include <x86intrin.h>
#endif

inline uint64_t rdtsc() {
unsigned int lo, hi;
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return ((uint64_t)hi << 32) | lo;
}

// DATA GENERATOR
void generate_large_json(const std::string& filename) {
std::cout << "Generating " << filename << " (~100MB)..." << std::endl;
std::ofstream out(filename);
out << "{ \"type\": \"FeatureCollection\", \"features\": [";
// 100MB target. Each entry is approx 2KB. 50,000 entries.
for (int i = 0; i < 50000; ++i) {
if (i > 0) out << ",";
out << R"({ "type": "Feature", "properties": { "name": "Region )" << i << R"(", "id": )" << i << R"(, "value": )" << (i * 1.234) << R"( }, "geometry": { "type": "Polygon", "coordinates": [[ )";
for (int j = 0; j < 50; ++j) {
if (j > 0) out << ",";
out << "[" << (double)i/100.0 + j << "," << (double)j/100.0 + i << "]";
}
out << "]] } }";
}
out << "] }";
}

// BENCHMARK RUNNER
struct Result {
double throughput_mbs;
double cycles_per_byte;
size_t alloc_count;
double duration_sec;
};

template<typename JsonType>
Result run_bench(const std::string& data) {
// Reset counters
g_alloc_count = 0;
g_alloc_bytes = 0;

auto start_time = std::chrono::high_resolution_clock::now();
uint64_t start_cycles = rdtsc();

// 1. Parse
auto j = JsonType::parse(data);

// 2. Access 5 nested keys
volatile double sum = 0;
// features[0].properties.value
// features[1000].geometry.type
// features[last].properties.id
// features[middle].type
// root.type

// Note: This access pattern assumes the structure generated above
// nlohmann/tachyon should support array indexing and object lookup

// Access logic requires knowledge of the structure.
// The structure is { "features": [ ... ] }
// We access "features" array.

auto& features = j["features"];

// Access 1
sum += (double)features[0]["properties"]["value"];
// Access 2
std::string type = features[1000]["geometry"]["type"];
// Access 3
sum += (int)features[features.size()-1]["properties"]["id"];
// Access 4
std::string featType = features[features.size()/2]["type"];
// Access 5
std::string rootType = j["type"];

// 3. Modify 1 value
features[0]["properties"]["name"] = "Modified Name";

// 4. Serialize back
std::string out = j.dump();

uint64_t end_cycles = rdtsc();
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> sec = end_time - start_time;

// Prevent optimization
(void)sum;
(void)type;
(void)featType;
(void)rootType;
(void)out.size();

double mbs = (data.size() / (1024.0 * 1024.0)) / sec.count();
double cpb = (double)(end_cycles - start_cycles) / data.size();

return {mbs, cpb, g_alloc_count.load(), sec.count()};
}

int main() {
std::string filename = "large_dataset.json";
{
std::ifstream f(filename);
if (!f.good()) {
generate_large_json(filename);
}
}

std::string data;
{
std::ifstream t(filename);
std::stringstream buffer;
buffer << t.rdbuf();
data = buffer.str();
}
std::cout << "Data Size: " << data.size() / (1024.0 * 1024.0) << " MB\n" << std::endl;

std::cout << "Running Nlohmann..." << std::endl;
Result res_nlohmann = run_bench<nlohmann::json>(data);

std::cout << "Running Tachyon..." << std::endl;
// For Tachyon, if we want to test "Zero malloc", we might need to reset the arena if we had one.
// But here we rely on the library logic.
Result res_tachyon = run_bench<tachyon::json>(data);

std::cout << "\n=== HEAD-TO-HEAD BENCHMARK ===\n" << std::endl;
std::cout << std::left << std::setw(15) << "Library"
<< std::setw(15) << "Throughput"
<< std::setw(15) << "Duration"
<< std::setw(15) << "Allocs"
<< std::setw(15) << "Cycles/Byte" << std::endl;
std::cout << std::string(75, '-') << std::endl;

std::cout << std::left << std::setw(15) << "Nlohmann"
<< res_nlohmann.throughput_mbs << " MB/s "
<< res_nlohmann.duration_sec << " s "
<< res_nlohmann.alloc_count << " "
<< res_nlohmann.cycles_per_byte << std::endl;

std::cout << std::left << std::setw(15) << "Tachyon"
<< res_tachyon.throughput_mbs << " MB/s "
<< res_tachyon.duration_sec << " s "
<< res_tachyon.alloc_count << " "
<< res_tachyon.cycles_per_byte << std::endl;

return 0;
}
Binary file added compat_test
Binary file not shown.
Binary file added compatibility_test
Binary file not shown.
Loading