HarperFast / HarperFast/harper
MQTT: intern per-subscription topic strings
- Dominant language
- JavaScript
- Stars
- 89
- Forks
- 10
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 200
Description
## Problem
Minor: each MQTT subscription retains ~3 fresh copies of its topic string (`Msg/topicN`, `/topicN`, `topicN` shapes measured at 15,000 copies each in a 15k-subscription local heap snapshot, ~1.1 MB) even when the workload has few distinct topics (29 in the measured production case). Topic strings arrive from packet parsing, so each subscribe allocates new strings; `DurableSubscriptionsSession` then retains them per subscription (`subscription.topic`, session records, contexts).
## Proposal
Intern the topic string once per session (or via a small bounded map) at `addSubscription` so duplicate subscriptions share one string. ~1 KB/connection at 15 subs/conn; trivial but only worth doing alongside other work in this file.
---
_Filed by an AI agent (Claude Code) from a subscription-path memory/CPU investigation._
Contributor guide
Research direction
Start at DurableSubscriptionsSession.addSubscription and trace how subscription.topic, session records, and contexts retain parsed topic strings. Confirm the current allocation and retention behavior, then verify that duplicate topics within a session share storage without changing subscription behavior or exceeding the intended memory bounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100