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
59 changes: 21 additions & 38 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
# Business Source License 1.1 (BSL)

**Software:** Tachyon JSON Library v0.7.2
**Licensor:** Tachyon Systems (by WilkOlbrzym-Coder)
**Change License:** MIT License
**Change Date:** January 1, 2030

### 1. LICENSE GRANT
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and use the Software subject to the conditions below.

### 2. ADDITIONAL USE GRANT (FREE TIER)
You may use the Software for any purpose, including production use, free of charge, provided that your **Annual Gross Revenue is less than $1,000,000 USD**. Attribution to the author is required.

### 3. COMMERCIAL USE LIMITATIONS
If your Annual Gross Revenue exceeds **$1,000,000 USD**, your use of the Software is limited to non-production use only (testing and development). Production use for entities above $1M revenue requires a separate commercial agreement. Suggested tiers:
* **$1M - $5M Revenue:** One-time perpetual license ($2,499 USD).
* **Over $5M Revenue:** Annual subscription models.

### 4. CORE PROTECTION
Users are strictly prohibited from extracting the SIMD structural kernels or the "Safe Depth Skip" logic for use in other libraries or projects. Reverse engineering of the core structural bitmask generation is forbidden.

### 5. BEST EFFORT BUG-FIX POLICY
The Licensor aims for the highest code quality and provides the following support policy:
* **Target Response:** If a critical bug (crash or incorrect result) is reported and reproduced, the Licensor will use reasonable efforts to provide a fix or workaround, typically within **14 business days**.
* **No Guarantee:** If a specific bug cannot be resolved within this timeframe or at all, the Licensor **assumes no responsibility or liability**. The attempt to fix is a courtesy, not a legal obligation.

### 6. NO WARRANTY AND LIMITATION OF LIABILITY
EXCEPT FOR THE POLICY IN SECTION 5, THE SOFTWARE IS PROVIDED **"AS IS"**, WITHOUT WARRANTY OF ANY KIND.
IN NO EVENT SHALL THE LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
If the Software fails to perform or causes damages, the Licensor is not responsible for any financial or data loss.

### 7. CHANGE TO OPEN SOURCE
On the **Change Date (January 1, 2030)**, this license will automatically expire, and the Software will be permanently licensed under the **MIT License**.

***
**Author:** WilkOlbrzym-Coder
**Brand:** Tachyon Systems
***
MIT License

Copyright (c) 2026 Tachyon Systems

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
134 changes: 29 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,47 @@
# Tachyon 0.7.2 "QUASAR" - The World's Fastest JSON Library
# Tachyon v8.0 "Supernova"

**Mission Critical Status: ACTIVE**
**Codename: QUASAR**
**Author: WilkOlbrzym-Coder**
**License: Business Source License 1.1 (BSL)**
**The Ultimate Hybrid JSON Library (C++11 / C++17)**

---
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.

## 🚀 Performance: At the Edge of Physics
## ⚡ Hybrid Architecture

Tachyon 0.7.2 is not just a library; it is a weapon of mass optimization. Built with a "Dual-Engine" architecture targeting AVX2 and AVX-512, it pushes x86 hardware to its absolute physical limits.
Tachyon adapts to your build environment:

### 🏆 Benchmark Results: AVX-512 ("God Mode")
*Environment: [ISA: AVX-512 | ITERS: 50 | WARMUP: 20]*
| 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 |

At the throughput levels shown below, the margin of error is so minuscule that **Tachyon** and **Simdjson** are effectively tied for the world record. Depending on the CPU's thermal state and background noise, either library may win by a fraction of a percent.
## 🚀 Performance

| Dataset | Library | Speed (MB/s) | Median Time (s) | Status |
|---|---|---|---|---|
| **Canada.json** | **Tachyon (Turbo)** | **10,538.41** | 0.000203 | 👑 **JOINT WORLD RECORD** |
| Canada.json | Simdjson (Fair) | 10,247.31 | 0.000209 | Extreme Parity |
| Canada.json | Glaze (Reuse) | 617.48 | 0.003476 | Obsolete |
| **Huge (256MB)** | **Simdjson (Fair)** | **2,574.96** | 0.099419 | 👑 **JOINT WORLD RECORD** |
| Huge (256MB) | Tachyon (Turbo) | 2,545.57 | 0.100566 | Extreme Parity |
| Huge (256MB) | Glaze (Reuse) | 379.94 | 0.673788 | Obsolete |
*Comparison vs Nlohmann JSON (v3.11.3)*

### 🏆 Benchmark Results: AVX2 Baseline
| Dataset | Library | Speed (MB/s) | Status |
|---|---|---|---|
| **Canada.json** | **Tachyon (Turbo)** | **6,174.24** | 🥇 **Dominant** |
| Canada.json | Simdjson (Fair) | 3,312.34 | Defeated |
| **Huge (256MB)** | **Tachyon (Turbo)** | **1,672.49** | 🥇 **Dominant** |
| Huge (256MB) | Simdjson (Fair) | 1,096.11 | Defeated |
| 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** |

---

## 🏛️ The Four Pillars of Quasar

### 1. Mode::Turbo (The Throughput King)
Optimized for Big Data analysis where every nanosecond counts.
* **Technology**: **Vectorized Depth Skipping**. Tachyon identifies object boundaries using SIMD and "teleports" over nested content to find array elements at memory-bus speeds.

### 2. Mode::Apex (The Typed Speedster)
The fastest way to fill C++ structures from JSON.
* **Technology**: **Direct-Key-Jump**. Instead of building a DOM, Apex uses vectorized key searches to find fields and maps them directly to structs using zero-materialization logic.

### 3. Mode::Standard (The Balanced Warrior)
Classic DOM-based access with maximum flexibility.
* **Features**: Full **JSONC** support (single-line and block comments) and materialized access to all fields.

### 4. Mode::Titan (The Tank)
Enterprise-grade safety for untrusted data.
* **Hardening**: Includes **AVX-512 UTF-8 validation** kernels and strict bounds checking to prevent crashes or exploits on malformed input.

---

## 🛠️ Usage Guide

### Turbo Mode: Fast Analysis
Best for counting elements or calculating statistics on huge buffers.

```cpp
#include "Tachyon.hpp"

Tachyon::Context ctx;
auto doc = ctx.parse_view(buffer, size); // Zero-copy view

if (doc.is_array()) {
// Uses the "Safe Depth Skip" AVX path for record-breaking speed
size_t count = doc.size();
}
```

### Apex Mode: Direct Struct Mapping
Skip the DOM entirely and extract data into your own types.
## 🛠️ Usage

**Drop-in Replacement**:
```cpp
struct User {
int64_t id;
std::string name;
};
// #include <nlohmann/json.hpp>
#include "tachyon.hpp"

// Non-intrusive metadata
TACHYON_DEFINE_TYPE_NON_INTRUSIVE(User, id, name)
using json = nlohmann::json; // Alias provided automatically

int main() {
Tachyon::json j = Tachyon::json::parse(json_string);
User u;
j.get_to(u); // Apex Direct-Key-Jump fills the struct instantly
json j = json::parse(R"({"fast": true})");
for (auto& [key, val] : j.items()) {
std::cout << key << ": " << val << "\n";
}
}
```

---

## 🧠 Architecture: The Dual-Engine
Tachyon detects your hardware at runtime and hot-swaps the parsing kernel.
* **AVX2 Engine**: 32-byte-per-cycle classification using `vpshufb` tables.
* **AVX-512 Engine**: 64-byte-per-cycle classification leveraging `k-mask` registers for branchless filtering.

---

## 🛡️ Licensing & Support Policy

**Business Source License 1.1 (BSL)**

Tachyon is licensed under the BSL. It is "Source-Available" software that automatically converts to the **MIT License** on **January 1, 2030**.

### Commercial Tiers:
* **Free (Tier 0)**: Annual Revenue < $1M USD. **FREE** for production use. Attribution required.
* **Paid (Tier 1-4)**: Annual Revenue > $1M USD. Requires a commercial agreement for production use.
* $1M - $5M Revenue: $2,499 (One-time payment).
* Over $5M Revenue: Annual subscription models.

### Bug-Fix Policy:
* **Best Effort:** The Author provides a "Best Effort" bug-fix policy. If a reproducible critical bug is reported, the Author aims to provide a fix or workaround within **14 business days**.
* **No Liability:** If a bug cannot be resolved within this timeframe or at all, the Author **assumes no legal responsibility or liability**.

**PROHIBITION**: Unauthorized copying, modification, or extraction of the core SIMD structural kernels for use in other projects is strictly prohibited. The software is provided **"AS IS"** without any product warranty.

---
## 📜 License

*(C) 2026 Tachyon Systems. Engineered by WilkOlbrzym-Coder.*
MIT License.
149 changes: 149 additions & 0 deletions benchmark_final.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include <iostream>
#include <vector>
#include <string>
#include <chrono>
#include <fstream>
#include <filesystem>
#include <iomanip>
#include <random>
#include <atomic>

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

// ALLOCATION TRACKER
std::atomic<size_t> g_alloc_count{0};
void* operator new(size_t size) {
g_alloc_count++;
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 GENERATORS
void generate_canada(const std::string& filename) {
std::ofstream out(filename);
out << "{ \"type\": \"FeatureCollection\", \"features\": [";
for (int i = 0; i < 5000; ++i) { // Reduced count for reasonable benchmark time but still large (~20MB)
if (i > 0) out << ",";
out << R"({ "type": "Feature", "properties": { "name": "Canada Region )" << i << R"(" }, "geometry": { "type": "Polygon", "coordinates": [[ )";
for (int j = 0; j < 20; ++j) {
if (j > 0) out << ",";
out << "[" << (double)i/100.0 << "," << (double)j/100.0 << "]";
}
out << "]] } }";
}
out << "] }";
}

void generate_unicode(const std::string& filename) {
std::ofstream out(filename);
out << "[";
for (int i = 0; i < 10000; ++i) {
if (i > 0) out << ",";
out << "\"English\", \"Русский text\", \"中文 characters\", \"Emoji 🚀 check\", \"Math ∀x∈R\"";
}
out << "]";
}

// BENCHMARK RUNNER
struct Result {
double speed_mbs;
double cycles_per_byte;
size_t allocs;
};

template<typename Func>
Result run_bench(const std::string& data, Func f) {
// Warmup
f();

g_alloc_count = 0;
auto start = std::chrono::high_resolution_clock::now();
uint64_t start_cycles = rdtsc();

f();

uint64_t end_cycles = rdtsc();
auto end = std::chrono::high_resolution_clock::now();

size_t allocs = g_alloc_count;
std::chrono::duration<double> sec = end - start;

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

return {mbs, cpb, allocs};
}

int main() {
std::cout << "Generating Data..." << std::endl;
generate_canada("canada.json");
generate_unicode("unicode.json");

std::string canada_str, unicode_str;
{ std::ifstream t("canada.json"); std::stringstream buffer; buffer << t.rdbuf(); canada_str = buffer.str(); }
{ std::ifstream t("unicode.json"); std::stringstream buffer; buffer << t.rdbuf(); unicode_str = buffer.str(); }

std::cout << "Canada Size: " << canada_str.size() / 1024.0 << " KB" << std::endl;
std::cout << "Unicode Size: " << unicode_str.size() / 1024.0 << " KB" << std::endl;

std::cout << "\n=== BENCHMARK: EAGER PARSE (FAIR FIGHT) ===\n" << std::endl;
std::cout << std::left << std::setw(15) << "Dataset"
<< std::setw(15) << "Library"
<< std::setw(15) << "Speed (MB/s)"
<< std::setw(15) << "Cycles/Byte"
<< std::setw(15) << "Allocs" << std::endl;
std::cout << std::string(75, '-') << std::endl;

auto print_row = [](const std::string& d, const std::string& l, const Result& r) {
std::cout << std::left << std::setw(15) << d
<< std::setw(15) << l
<< std::setw(15) << r.speed_mbs
<< std::setw(15) << r.cycles_per_byte
<< std::setw(15) << r.allocs << std::endl;
};

// Canada Nlohmann
print_row("canada.json", "Nlohmann", run_bench(canada_str, [&](){
auto j = nlohmann::json::parse(canada_str);
(void)j.size();
}));

// Canada Tachyon
print_row("canada.json", "Tachyon", run_bench(canada_str, [&](){
auto j = tachyon::json::parse(canada_str);
(void)j.size();
}));

// Unicode Nlohmann
print_row("unicode.json", "Nlohmann", run_bench(unicode_str, [&](){
auto j = nlohmann::json::parse(unicode_str);
(void)j.size();
}));

// Unicode Tachyon
print_row("unicode.json", "Tachyon", run_bench(unicode_str, [&](){
auto j = tachyon::json::parse(unicode_str);
(void)j.size();
}));

return 0;
}
Loading