I'm the author of umbot, an open-source TypeScript framework for messaging bots and voice assistants. (Disclaimer: I am obviously biased, so take my benchmarks with a grain of salt. To keep it fair, I included a single-dispatcher control for grammY to show it's not just a framework issue, but an architectural one). While benchmarking it against grammY and Telegraf, I got a much bigger gap than I expected. My first thought was that I'd messed up the benchmark, so I started looking at what actually happens before a handler runs.
The most useful finding was how much work happens before the selected handler runs.
TL;DR: In one warmed-up routing probe with 1,000 rules, umbot created 2 Promise resources, grammY with individual listeners created 6,014, and Telegraf created 8,013. A single synchronous dispatcher inside grammY brought its count to 16. That control is the point of this post: how dispatch is organized changes the amount of work per update. For reference, per-update latency in the same warmed-up setup kept the same ordering: at 1,000 rules, umbot was ~1.3 µs, the single-dispatcher grammY control ~8 µs, and individual-listener chains ~300 µs. Latency numbers vary by machine; the counts remain the subject of this post. These counts don't measure end-to-end latency or allocated bytes.
The workload
The benchmark feeds Telegram update objects into each framework's update-processing entry point. Network calls and database operations are excluded. For grammY and Telegraf, bot information is supplied explicitly so initialization doesn't call Telegram's `getMe` API.
The competitors register individual `hears` handlers. String slots in umbot use substring matching, so the corresponding competitor triggers use escaped regular expressions with the same substring behavior. Matching rules are placed halfway through the registered list.
For this post, I narrowed the question to the Promise resources created while processing one warmed-up update. I'm leaving throughput rankings out and including a single-dispatcher control within grammY.
Why the architecture matters
In this setup, grammY and Telegraf compose the registered listeners as middleware. Reaching a rule halfway through a large list means passing through the earlier listeners. Those transitions have a cost beyond checking a string or a regular expression.
umbot uses a different internal search structure:
- Exact lookup: a hash map handles eligible exact matches.
- Substring lookup: larger literal rule sets use an Aho–Corasick index, so each phrase doesn't require its own middleware traversal. The trie is stored in flat typed arrays; edge lookup uses binary search.
- Regex prefiltering: when a required literal can be safely extracted from a regex, its absence rules that expression out. A positive prefilter result still needs the real regex check. Expressions without a usable literal remain candidates.
- Reusable search buffers: candidate positions and matched-literal IDs use preallocated buffers rather than fresh per-rule async closures.
I also checked the worst case for these structures: 1,000 anchored patterns with no safely extractable literal, so prefiltering rejects nothing and routing degrades to a linear candidate scan. Even there the scan stayed about 10× cheaper per update than the middleware chain, because testing candidates without per-listener composition is cheaper.
The internals also avoid unnecessary async wrappers and initialize things such as buttons, cards, NLU and regex match results lazily. The public update-processing method still returns a Promise; this isn't a claim of zero allocations per update.
There's a cost on the other side: indexes take time and memory to build. Tiny rule sets use simpler paths, and registration/startup should be measured separately from warmed-up routing. Concretely, on this machine registering 1,000 regex rules takes umbot ~9 ms versus ~1.4 ms in grammY — the cost of ReDoS validation and prefilter construction. String-slot registration is at parity. Both run once at startup, not per update.
Counting the Promise resources
To check the middleware explanation directly, I used `async_hooks` to count `PROMISE` initialization events around one warmed-up exact match in the middle of the list:
| Configuration | 6 rules | 1,000 rules |
|---|
| umbot | 2 | 2 |
| grammY, individual hears handlers | 50 | 6014 |
| Telegraf, individual hears handlers | 61 | 8013 |
| grammY, one text handler with a synchronous substring loop | 16 | 16 |
This diagnostic ran on Node 24.21.0, V8 13.6, Windows x64, with grammY 1.46.0 and Telegraf 4.16.3. Counts include the probe's own `await`. Hooks add overhead, so I didn't use this instrumented run to measure latency. These are resource-initialization counts, not allocated bytes or simultaneously live objects.
The last row is important. You can change how routing is organized inside grammY too. A single handler doing synchronous dispatch doesn't pay the same per-listener Promise cost. A follow-up latency run on the same machine, with handler outcomes verified by counters, still put the control well above umbot: roughly 2.5–11× slower at 1,000 rules depending on match type, and near-parity at 6 rules. That is expected — a linear `includes` scan over 1,000 slots is still more work than an indexed lookup.
That is the architectural comparison I find interesting: an indexed command router versus a long chain of independently composed listeners. It also suggests a useful control for future comparisons: keep the framework, change only the dispatch structure.
Under concurrency, more transient objects can increase GC pressure. That is a plausible contributor to the larger gaps in stress runs, but assigning a specific fraction of the speedup to GC or to an individual optimization needs a separate measurement.
What I would and wouldn't conclude
The counts support a substantial difference in Promise creation for these routing configurations. They don't establish the best possible performance of every application built with the other frameworks, or tell us exactly how much time each optimization saves. A bot with six commands, external API calls and database work has a different cost profile.
With real I/O, network waiting can dominate response time while routing still consumes CPU. Reducing that work and transient allocations can matter even when users see little change in latency. These Promise counts alone don't quantify the CPU or memory savings of a complete application.
A separate experiment I'd run is a local HTTP server returning delayed responses, rate-limit errors and timeouts. That would let me check pending-request memory, queues and recovery under controlled conditions. Live API checks would cover compatibility; the local server would cover repeatable load. Those experiments haven't been performed here.
I also found things to improve in my stress harness: its advertised regex traffic wasn't actually registering separate regex rules, and timer-based heap sampling could collect zero samples during a continuously replenished microtask workload. I'm leaving the stress RPS and memory charts out of this post until those measurements are tightened up.
Reproduce and inspect
The benchmark sources are in the repository:
git clone https://github.com/max36895/umbot.git
cd umbot
npm install
npm run build
npm install --prefix benchmark/comparison
npm run compare
Record the commit, Node version and installed dependency versions when comparing runs. Results will vary by machine and revision; a development working tree also needs its actual changes recorded.
npm install umbot
Link:
Benchmark setup: https://github.com/max36895/umbot/blob/main/benchmark/comparison/
I've kept the links minimal in the main post to avoid triggering Reddit's spam filters. I'll drop the direct file links in the comments below.
The diagnostic below can be saved as `redit/promise-probe.cjs` inside the checkout and run with node redit/promise-probe.cjs. It counts one request after warm-up, including a single-handler grammY control.
If you maintain a high-throughput Node.js router, I'd be interested in which control you'd add next: the same indexed dispatcher inside each framework, randomized matching positions, or a more representative set of real conversation rules?
Promise-count diagnostic
// Diagnostic Promise counting; do not use the timings from this run as a benchmark.
const path = require('path');
const { createHook } = require('async_hooks');
const bench = path.resolve(__dirname, '../benchmark/comparison');
const { buildBenchOptions } = require(path.join(bench, 'telegram.js'));
const { umbotParticipant } = require(path.join(bench, 'runner.js'));
(async () => {
const results = [];
for (const count of [6, 1000]) {
const opts = buildBenchOptions();
const scenario = { cmds: count, kind: 'text', hit: 'exact' };
const participants = [umbotParticipant(opts), ...opts.competitors];
// The same gram, but one routing point with the usual synchronous enumeration.
const grammy = opts.competitors.find((fw) => fw.name === 'grammy');
participants.push({
name: 'grammy-single-router',
make: grammy.make,
setup: (bot) => {
const slots = Array.from({ length: count }, (_, i) => `cmd_${i}_`);
bot.on('message:text', (ctx) => {
for (const slot of slots) {
if (ctx.message.text.includes(slot)) return;
}
});
},
run: grammy.run,
});
for (const fw of participants) {
const instance = fw.make();
fw.setup(instance, scenario);
await new Promise((resolve) => setTimeout(resolve, 100));
const text = `cmd_${Math.floor(count / 2)}_`;
for (let i = 0; i < 100; i++) await fw.run(instance, text, i);
let promises = 0;
const hook = createHook({
init(_id, type) {
if (type === 'PROMISE') promises++;
},
});
hook.enable();
await fw.run(instance, text, 1001);
hook.disable();
results.push({
participant: fw.name,
commands: count,
promiseInitsIncludingProbeAwait: promises,
});
}
}
console.log(JSON.stringify(results, null, 2));
})().catch((error) => {
console.error(error);
process.exitCode = 1;
});