Skip to content

aka-l/tinyframejs

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

71 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TinyFrameJS

TinyFrameJS constitutes an advanced, high-performance JavaScript framework tailored for processing large-scale tabular and financial data. Architected atop a bespoke in-memory representation inspired by columnar data paradigms (such as Pandas), TinyFrameJS is rigorously optimized for the JavaScript runtime ecosystem.

It leverages TypedArray-based memory management to enable low-latency, high-throughput operations, offering computational efficiency approaching that of systems implemented in native code, but with the accessibility and flexibility of JavaScript.


πŸš€ Mission Statement

TinyFrameJS endeavors to establish a scalable, memory-efficient, and performant infrastructure for analytical and quantitative workflows in JavaScript. It obviates the need to offload workloads to Python or R by providing a native, fluent API for statistical computation, data transformation, and time-series modeling directly within the JS execution environment (Node.js or browser).


πŸ”₯ Core Differentiators

  • Entirely JavaScript-native with zero binary dependencies (no WebAssembly or C++ bindings required)
  • Operates directly on Float64Array and Int32Array structures to ensure dense memory layout and consistent type uniformity
  • Achieves 10Γ— to 100Γ— performance gains over traditional JS object/array workflows
  • DataFrame prototype is auto-extended at runtime; no manual augmentation or external registration required
  • Modular design enables method-level tree-shaking for highly customized builds

Released under the MIT license, ensuring unrestricted academic and commercial application.


πŸ“Š Benchmark Results (vs competitors)

Operation tinyframejs Pandas (Python) Data-Forge (JS) Notes
rollingMean βœ… ~50ms 🟒 ~5ms ❌ ~400ms JS now on par with Python
normalize βœ… ~35ms 🟒 ~6ms ❌ ~300ms Memory: 10x more efficient
corrMatrix βœ… ~60ms 🟒 ~8ms ❌ ~500ms TypedArray wins
dropNaN βœ… ~20ms 🟒 ~20ms ❌ ~100ms Parity achieved

All results measured on 100,000 rows Γ— 10 columns. See benchmark_tiny.js for test script.


πŸ“¦ Project Structure Overview

src/
β”œβ”€β”€ core/                # Foundational logic: validators, type guards, runtime enforcement
β”œβ”€β”€ io/                  # Input/output abstraction layer: CSV, XLSX, JSON, SQL, APIs
β”œβ”€β”€ methods/             # Modular operations: aggregation, filtering, sorting, transforms, rolling
β”‚   β”œβ”€β”€ aggregation/
β”‚   β”œβ”€β”€ filtering/
β”‚   β”œβ”€β”€ sorting/
β”‚   β”œβ”€β”€ transform/
β”‚   β”œβ”€β”€ rolling/
β”‚   β”œβ”€β”€ raw.js           # Unified export of method definitions
β”‚   β”œβ”€β”€ inject.js        # Dependency injection wrapper for stateful functions
β”‚   └── autoExtend.js    # Runtime auto-extension of DataFrame.prototype
β”œβ”€β”€ frame/               # TinyFrame core representation + DataFrame chainable API class
β”œβ”€β”€ display/             # Rendering modules for console and web visualization
β”œβ”€β”€ utils/               # Low-level array, math, and hashing utilities
β”œβ”€β”€ loader.js            # Global pre-initialization logic (invokes auto-extension)
β”œβ”€β”€ types.js             # Global TS type definitions
└── index.js             # Public API surface of the library

🧠 Architecture Design

Data Flow Pipeline

TinyFrameJS follows a clear data flow from raw inputs to the fluent API:

graph TD
    input[Raw Data: CSV, JSON, API] --> reader[reader.js]
    reader --> createFrame[createFrame.js]
    createFrame --> tf[TinyFrame Structure]
    tf --> df[DataFrame Wrapper]
    df --> auto[Auto-Extended Methods]
    auto --> user["User API: df.sort().dropNaN().head().count()"]
Loading

Auto-Extension Mechanism

One of TinyFrameJS's key innovations is its automatic method extension:

  1. All methods are defined as pure, curried functions with dependency injection
  2. The inject.js module centralizes dependencies like validators
  3. The autoExtend.js module automatically attaches all methods to DataFrame.prototype
  4. This happens once at runtime initialization

This approach provides several benefits:

  • Zero boilerplate: No manual registration of methods
  • Tree-shakable: Unused methods can be eliminated by bundlers
  • Fluent API: Methods can be chained naturally
  • Clean separation: Core logic vs. API surface

Method Types

TinyFrameJS methods fall into two categories:

  1. Transformation methods (e.g., sort(), dropNaN(), head())

    • Return a new DataFrame instance
    • Can be chained with other methods
  2. Aggregation methods (e.g., count(), mean(), sum())

    • Return a scalar value or array
    • Typically terminate a method chain

Example of combined usage:

// Chain transformations and end with aggregation
const result = df
  .sort('price') // transformation β†’ returns new DataFrame
  .dropNaN('volume') // transformation β†’ returns new DataFrame
  .head(10) // transformation β†’ returns new DataFrame
  .mean('price'); // aggregation β†’ returns number

🧠 API Design Paradigm

Instantiation

import { DataFrame } from 'tinyframejs';

const df = new DataFrame({
  date: ['2023-01-01', '2023-01-02'],
  price: [100, 105],
  volume: [1000, 1500],
});

Declarative Transformation Pipeline

const top10 = df.sort('price').dropNaN('price').head(10).count('price');

Core methods include:

  • Row-wise transformations: dropNaN, fillNaN, head, sort, diff, cumsum
  • Aggregations: count, mean, sum, min, max
  • Rolling statistics: rollingMean, rollingStd, etc.

All methods are automatically attached via runtime bootstrap β€” no explicit extension required.

Grouped Aggregation

const grouped = df.groupBy(['sector']).aggregate({
  price: 'mean',
  volume: 'sum',
});

Reshape Operations

df.pivot('date', 'symbol', 'price');
df.melt(['date'], ['price', 'volume']);

Additional idioms and usage scenarios available in examples/.


πŸš€ Future Enhancements

TinyFrameJS roadmap includes several performance-focused enhancements:

StreamingFrame

For processing massive datasets that don't fit in memory:

  • Chunk-based processing of large files
  • Streaming API for continuous data ingestion
  • Memory-efficient operations on datasets with 10M+ rows

LazyPipeline

For optimized execution of complex transformations:

  • Deferred execution until results are needed
  • Automatic operation fusion and optimization
  • Reduced intermediate allocations

Memory Optimization

  • Batch mutations to reduce allocations
  • Improved encapsulation of internal structures
  • Optimized cloning strategies for transformations

πŸ›  Development Workflow

npm run lint        # Lint codebase with ESLint
npm run build       # Compile into dist/
npm run test        # Execute unit tests (Vitest)
npm run benchmark   # Launch performance suite

CI/CD is automated via GitHub Actions + Changesets. See ci.yml.


πŸ›£ Roadmap

  • Fully declarative DataFrame interface
  • TypedArray-powered core computation
  • Auto-attached methods via runtime extension
  • Competitive performance with compiled backends
  • Expand statistical/transform methods and rolling ops
  • StreamingFrame: chunk-wise ingestion for massive datasets
  • Lazy evaluation framework: .pipe() + deferred execution
  • WebAssembly integration for CPU-bound operations
  • Documentation with real-time interactive notebooks

🀝 Contributing Guidelines

  • Fork β†’ Feature Branch β†’ Pull Request
  • Adopt Conventional Commits (e.g., feat:, fix:, docs:)
  • Ensure all changes pass lint, test, and CI gates

Refer to CONTRIBUTING.md for detailed guidelines.


πŸ§‘β€πŸ’» Developer

Made with ❀️ by @a3ka


🌟 Support the Project

If you like what we're building, please consider:

  • ⭐️ Starring this repository
  • 🐦 Sharing on Twitter / Reddit
  • πŸ‘¨β€πŸ’» Submitting a PR
  • πŸ’¬ Giving feedback in Discussions

Together we can bring efficient data tools to the web.


πŸ“œ License

MIT Β© TinyFrameJS authors. Use freely. Build boldly.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.9%
  • Shell 0.1%