|
1 | | -# ⚡ B-FAST Documentation |
| 1 | +# ⚡ B-FAST (Binary Fast Adaptive Serialization Transfer) |
2 | 2 |
|
3 | | -B-FAST (Binary Fast Adaptive Serialization Transfer) é um protocolo de serialização binária de ultra-alta performance para Python e TypeScript. |
| 3 | +B-FAST is an ultra-high performance binary serialization protocol, developed in Rust for Python and TypeScript ecosystems. It's designed to replace JSON in critical routes where latency, CPU usage, and bandwidth are bottlenecks. |
4 | 4 |
|
5 | | -## Características Principais |
6 | | -- **Motor Rust:** Serialização nativa sem overhead do interpretador Python |
7 | | -- **Pydantic Native:** Lê modelos Pydantic diretamente da memória |
8 | | -- **Zero-Copy NumPy:** Serializa arrays na velocidade máxima de I/O |
9 | | -- **String Interning:** Chaves repetidas enviadas apenas uma vez |
10 | | -- **LZ4 Integrado:** Compressão ultra-veloz para payloads grandes |
| 5 | +## 🚀 Why B-FAST? |
11 | 6 |
|
12 | | -## Performance |
13 | | -- **15x mais rápido** que JSON padrão |
14 | | -- **3x mais rápido** que orjson |
15 | | -- **80% menor** payload comparado ao JSON |
| 7 | +- **Rust Engine:** Native serialization without Python interpreter overhead |
| 8 | +- **Pydantic Native:** Reads Pydantic model attributes directly from memory, skipping the slow .model_dump() process |
| 9 | +- **Zero-Copy NumPy:** Serializes tensors and numeric arrays directly, achieving maximum memory I/O speed |
| 10 | +- **String Interning:** Repeated keys (like field names in object lists) are sent only once |
| 11 | +- **Bit-Packing:** Small integers and booleans occupy only 4 bits within the type tag |
| 12 | +- **Built-in LZ4:** Ultra-fast block compression for large payloads |
16 | 13 |
|
17 | | -## Guias de Uso |
18 | | -- [Início Rápido](getting_started.md) - Instalação e primeiros passos |
19 | | -- [Frontend TypeScript](frontend.md) - Integração com aplicações web |
20 | | -- [Otimização](performance.md) - Dicas para máxima performance |
21 | | -- [Troubleshooting](troubleshooting.md) - Solução de problemas comuns |
| 14 | +## 📊 Performance |
22 | 15 |
|
23 | | -## About B-FAST |
| 16 | +Comparison of serializing a list of 10,000 complex Pydantic models: |
24 | 17 |
|
25 | | -B-FAST represents more than just a serialization library—it's a testament to the power of open knowledge sharing. |
| 18 | +### 🚀 Serialization (Encode) |
| 19 | +| Format | Time (ms) | Speedup | Payload Size | Reduction | |
| 20 | +|--------|-----------|---------|--------------|-----------| |
| 21 | +| JSON (Standard) | 9.64ms | 1.0x | 1.18 MB | 0% | |
| 22 | +| orjson | 1.51ms | 6.4x | 1.06 MB | 10.2% | |
| 23 | +| Pickle | 2.74ms | 3.5x | 808 KB | 31.6% | |
| 24 | +| **B-FAST** | **4.51ms** | **2.1x** | **998 KB** | **15.5%** | |
| 25 | +| **B-FAST + LZ4** | **5.21ms** | **1.9x** | **252 KB** | **78.7%** | |
26 | 26 |
|
27 | | -> *"Knowledge is the only wealth that grows when we share it"* |
| 27 | +### 🔄 Round-Trip (Encode + Network + Decode) |
28 | 28 |
|
29 | | -This philosophy drives every aspect of B-FAST's development. By making high-performance binary serialization accessible to Python and TypeScript developers, we're contributing to a more efficient and capable web ecosystem. |
| 29 | +#### 📡 100 Mbps (Slow Network) |
| 30 | +| Format | Total Time | Speedup vs JSON | |
| 31 | +|--------|------------|-----------------| |
| 32 | +| JSON | 114.3ms | 1.0x | |
| 33 | +| orjson | 92.3ms | 1.2x | |
| 34 | +| **B-FAST + LZ4** | **28.3ms** | **🚀 4.0x** | |
30 | 35 |
|
31 | | -**Created by:** marcelomarkus |
32 | | -**Mission:** Democratize high-performance serialization through open-source innovation |
33 | | -**Community:** Built for developers, by developers who believe in sharing knowledge |
| 36 | +#### 📡 1 Gbps (Fast Network) |
| 37 | +| Format | Total Time | Speedup vs JSON | |
| 38 | +|--------|------------|-----------------| |
| 39 | +| JSON | 29.3ms | 1.0x | |
| 40 | +| orjson | 15.9ms | 1.8x | |
| 41 | +| **B-FAST + LZ4** | **10.2ms** | **🚀 2.9x** | |
| 42 | + |
| 43 | +## 🎯 Ideal Use Cases |
| 44 | + |
| 45 | +- **📱 Mobile/IoT**: 78.7% data savings + 2.1x performance |
| 46 | +- **🌐 APIs over slow networks**: Up to 4x faster than JSON |
| 47 | +- **📊 Data pipelines**: 148x speedup for NumPy arrays |
| 48 | +- **🗜️ Storage/Cache**: Superior integrated compression |
| 49 | + |
| 50 | +## 📦 Installation |
| 51 | + |
| 52 | +### Backend (Python) |
| 53 | +```bash |
| 54 | +pip install bfast-py |
| 55 | +``` |
| 56 | + |
| 57 | +### Frontend (TypeScript) |
| 58 | +```bash |
| 59 | +npm install bfast-client |
| 60 | +``` |
| 61 | + |
| 62 | +## 🛠️ Basic Usage |
| 63 | + |
| 64 | +### Python |
| 65 | +```python |
| 66 | +import b_fast |
| 67 | +from pydantic import BaseModel |
| 68 | + |
| 69 | +class User(BaseModel): |
| 70 | + id: int |
| 71 | + name: str |
| 72 | + email: str |
| 73 | + |
| 74 | +# Create encoder |
| 75 | +bf = b_fast.BFast() |
| 76 | + |
| 77 | +# Sample data |
| 78 | +users = [User(id=i, name=f"User {i}", email=f"user{i}@example.com") for i in range(1000)] |
| 79 | + |
| 80 | +# Serialize |
| 81 | +data = bf.encode_packed(users, compress=True) |
| 82 | +print(f"Size: {len(data)} bytes") |
| 83 | + |
| 84 | +# Deserialize |
| 85 | +decoded = bf.decode_packed(data) |
| 86 | +``` |
| 87 | + |
| 88 | +### TypeScript |
| 89 | +```typescript |
| 90 | +import { BFastDecoder } from 'bfast-client'; |
| 91 | + |
| 92 | +async function loadData() { |
| 93 | + const response = await fetch('/api/users'); |
| 94 | + const buffer = await response.arrayBuffer(); |
| 95 | + |
| 96 | + // Decode and decompress automatically |
| 97 | + const users = BFastDecoder.decode(buffer); |
| 98 | + console.log(users); |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## 🔗 Useful Links |
| 103 | + |
| 104 | +- [Getting Started](getting_started.md) - Complete tutorial |
| 105 | +- [Frontend](frontend.md) - TypeScript integration |
| 106 | +- [Performance](performance.md) - Detailed technical analysis |
| 107 | +- [Troubleshooting](troubleshooting.md) - Troubleshooting guide |
| 108 | + |
| 109 | +## 📄 License |
| 110 | + |
| 111 | +Distributed under the MIT License. See [LICENSE](https://github.com/marcelomarkus/b-fast/blob/main/LICENSE) for more information. |
0 commit comments