How FIBJS Refactors Async and ORM for Faster Backend Performance

This article examines FIBJS's transition from callback‑based asynchronous code to coroutine‑based sync style, compares its ORM refactor and worker‑thread handling with NodeJS, and presents performance metrics that show memory and throughput improvements across various workloads.

Alibaba Terminal Technology
Alibaba Terminal Technology
Alibaba Terminal Technology
How FIBJS Refactors Async and ORM for Faster Backend Performance

FIBJS Module Refactor – From Callbacks to Coroutines

FIBJS, a versatile JavaScript runtime used for browsers, machine learning, robotics, and embedded applications, traditionally relied on callbacks for asynchronous operations, leading to complex execution order and "callback hell". The refactor introduces coroutine‑based locks that allow developers to write code that appears synchronous while still handling asynchronous tasks efficiently.

Promise and async/await Approaches

While Promise and async/await can linearise asynchronous flows, they still suffer from "async contagion" because the surrounding code continues executing before the promise resolves. FIBJS proposes a lightweight lock primitive that blocks execution until a signal is released, offering a more deterministic flow.

FIBJS ORM Refactor

The original FIBJSORM, migrated from Node ORM2, used callback‑heavy patterns that degraded performance. After refactoring, the ORM directly returns results without callbacks, reducing overhead. Benchmarks show that writing 100,000 rows improved from 4,694 TPS to 5,017 TPS.

Synchronous Programming Style in FIBJS

FIBJS leverages coroutines to manage multiple asynchronous tasks with lightweight locks. By creating many locks (e.g., lock1, lock2) and releasing them at specific points, developers can guarantee the order of task completion without nesting callbacks, promises, or async/await.

Comparison with NodeJS

NodeJS handles database requests with callbacks, leading to deep nesting and potential performance penalties. FIBJS replaces callbacks with direct result returns, offering cleaner code and slightly better throughput. In high‑volume writes (e.g., 1,000,000 rows), FIBJS outperforms NodeJS by reducing memory usage and execution time.

Concurrency and Worker Threads

Intensive computations such as UUID generation can be offloaded to Worker threads. Benchmarking on macOS shows that moving these tasks to workers reduces write time for 100,000 rows by about 2 seconds and narrows the gap for larger datasets.

Performance Metrics

As concurrency scales from 10,000 to 1,000,000 requests, FIBJS consistently uses less memory than NodeJS while maintaining comparable throughput. Version 0.26 of FIBJS shows improvements over earlier releases in thread scheduling and resource utilization.

Summary

FIBJS's refactor replaces callback‑driven async flows with coroutine‑based synchronization and moves CPU‑intensive tasks to worker threads, resulting in cleaner code and modest performance gains. These techniques are applicable to NodeJS projects seeking to reduce callback complexity and improve resource efficiency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceconcurrencyasync programmingFIBJSNodeJS ComparisonORM Refactor
Alibaba Terminal Technology
Written by

Alibaba Terminal Technology

Official public account of Alibaba Terminal

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.