Skip to main content

⚡ B-FAST (Binary Fast Adaptive Serialization Transfer) - Protocolo de serialização binária de ultra-alta performance, desenvolvido em Rust para o ecossistema Python e TypeScript

Project description

⚡ B-FAST (Binary Fast Adaptive Serialization Transfer)

O B-FAST é um protocolo de serialização binária de ultra-alta performance, desenvolvido em Rust para o ecossistema Python e TypeScript. Ele foi projetado para substituir o JSON em rotas críticas onde latência, uso de CPU e largura de banda são gargalos.

📚 Documentação

Documentação completa disponível em: https://marcelomarkus.github.io/b-fast/

🚀 Por que B-FAST?

  • Motor Rust: Serialização nativa sem o overhead do interpretador Python.
  • Pydantic Native: Lê atributos de modelos Pydantic diretamente da memória, pulando o lento processo de .model_dump().
  • Zero-Copy NumPy: Serializa tensores e arrays numéricos diretamente, atingindo a velocidade máxima de I/O de memória.
  • String Interning: Chaves repetidas (como nomes de campos em listas de objetos) são enviadas apenas uma vez.
  • Bit-Packing: Inteiros pequenos e booleanos ocupam apenas 4 bits dentro da tag de tipo.
  • LZ4 Integrado: Compressão de blocos ultra-veloz para payloads grandes.

📊 Benchmark (Latência Média)

Comparação de serialização de uma lista de 10.000 modelos Pydantic complexos:

🚀 Serialização (Encode)

Formato Tempo (ms) Speedup Tamanho do Payload Redução
JSON (Standard) 10.14ms 1.0x 1.18 MB 0%
orjson 1.55ms 6.6x 1.06 MB 10%
Pickle 2.73ms 3.7x 808 KB 32%
B-FAST 4.67ms 2.2x 998 KB 15%
B-FAST + LZ4 5.27ms 1.9x 252 KB 79%

🔄 Round-Trip (Encode + Network + Decode)

Teste completo incluindo transferência de rede e deserialização:

📡 100 Mbps (Rede Lenta)

Formato Tempo Total Speedup vs JSON
JSON 114.3ms 1.0x
orjson 92.3ms 1.2x
B-FAST + LZ4 28.3ms 🚀 4.0x

📡 1 Gbps (Rede Rápida)

Formato Tempo Total Speedup vs JSON
JSON 29.3ms 1.0x
orjson 15.9ms 1.8x
B-FAST + LZ4 10.2ms 🚀 2.9x

📡 10 Gbps (Rede Ultra-Rápida)

Formato Tempo Total Speedup vs JSON
JSON 20.8ms 1.0x
orjson 8.3ms 2.5x
B-FAST + LZ4 8.4ms 🚀 2.5x

🎯 Casos de Uso Ideais

  • 📱 Mobile/IoT: 79% economia de dados + 2.2x performance
  • 🌐 APIs com rede lenta: Até 4x mais rápido que JSON
  • 📊 Data pipelines: 148x speedup para NumPy arrays
  • 🗜️ Storage/Cache: Compressão superior integrada

📦 Instalação

Backend (Python)

uv add bfast-py

ou

pip install bfast-py

Frontend (TypeScript)

npm install bfast-client

🛠️ Como usar

1. No FastAPI (Integração Direta)

O B-FAST se integra perfeitamente como uma classe de resposta.

from fastapi import FastAPI, Response
from pydantic import BaseModel
import b_fast

class BFastResponse(Response):
    media_type = "application/x-bfast"
    
    def __init__(self, content=None, *args, **kwargs):
        super().__init__(content, *args, **kwargs)
        self.encoder = b_fast.BFast()

    def render(self, content) -> bytes:
        return self.encoder.encode_packed(content, compress=True)

app = FastAPI()

class User(BaseModel):
    id: int
    name: str

@app.get("/users", response_class=BFastResponse)
async def get_users():
    return [User(id=i, name=f"User {i}") for i in range(1000)]

2. No Frontend (React / Vue / Angular)

import { BFastDecoder } from 'bfast-client';

async function loadData() {
    const response = await fetch('/users');
    const buffer = await response.arrayBuffer();
    
    // Decodifica e descomprime LZ4 automaticamente
    const users = BFastDecoder.decode(buffer);
    console.log(users);
}

About B-FAST

"Performance is not just about speed—it's about efficiency where it matters most"

B-FAST was born from the recognition that modern applications need more than just fast serialization—they need smart serialization that adapts to real-world constraints. After extensive optimization achieving 2.2x faster serialization and 79% payload reduction, B-FAST has found its perfect niche in bandwidth-constrained environments.

Key Achievements:

  • 🚀 4.0x faster than JSON on 100 Mbps networks (round-trip)
  • 📦 79% smaller payloads with built-in LZ4 compression
  • 148x speedup for NumPy arrays
  • 🎯 Competitive even on ultra-fast 10 Gbps networks

Developed by: marcelomarkus

Philosophy: We believe that the future of data transfer lies not in raw CPU speed alone, but in intelligent protocols that minimize network overhead while maintaining excellent performance. B-FAST represents our contribution to a more efficient, bandwidth-conscious web.

📄 Licença

Distribuído sob a licença MIT. Veja LICENSE para mais informações.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bfast_py-1.0.7-cp38-abi3-win_amd64.whl (158.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

bfast_py-1.0.7-cp38-abi3-manylinux_2_34_x86_64.whl (314.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

bfast_py-1.0.7-cp38-abi3-macosx_11_0_arm64.whl (267.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file bfast_py-1.0.7-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: bfast_py-1.0.7-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 158.0 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for bfast_py-1.0.7-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f29eb074004492351ce518c0e59e8a10caf8f83fcb9a08ae0e1bf9cdeb30afc9
MD5 9ed49c71c884bd5fae63eaf59a9b90fe
BLAKE2b-256 960b2386629404a973f58824441ebda15196be0e68f83faa8cac0daa082b3ef0

See more details on using hashes here.

File details

Details for the file bfast_py-1.0.7-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for bfast_py-1.0.7-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 843857f050ca3742d2474f4d4883ba59afb7c823afa580494be0a1582e3b0726
MD5 cf7742e8aff3857ca09694560ff44493
BLAKE2b-256 2b410bb6035c05e59c8511aa729bfe146e25548c3590ecc420022212c28fd154

See more details on using hashes here.

File details

Details for the file bfast_py-1.0.7-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bfast_py-1.0.7-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98f81eda3da5493c7aa0f8a6e8d08cb886d3d24a7d0622037fa66246f9faf4e7
MD5 0a796da1fded2ff3ea32e2bdc85c5bda
BLAKE2b-256 e2c5129506c7e501a37b2fac712e5edcf902b7c3cff719cf5ba869a7ae331403

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page