Skip to content

perf(openapi): use set for operation ids - #241

Merged
mcollina merged 1 commit into
platformatic:mainfrom
rozzilla:perf/openapi/use-set-for-operation-ids
Nov 6, 2026
Merged

mcollina merged 1 commit into
platformatic:mainfrom
rozzilla:perf/openapi/use-set-for-operation-ids

Conversation

@rozzilla

@rozzilla rozzilla commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Speed up operation ID generation for large API specifications by replacing array-based operation-ID tracking with a Set for internal bulk generation, while keeping array support for existing callers. An internal local benchmark improved from 32.36 ms to 7.88 ms.

You can reproduce the comparison from the repository root with the current code:

node --input-type=module -e '
import { performance } from "node:perf_hooks"
import { generateOperationId } from "./packages/massimo/index.js"

function runBatch (makeAccumulator) {
  const all = makeAccumulator()
  for (let index = 0; index < 5000; index++) {
    generateOperationId(`/items/${index}`, "get", { operationId: `getItem${index}` }, all)
  }
}

function measure (makeAccumulator) {
  runBatch(makeAccumulator)
  const start = performance.now()
  for (let run = 0; run < 3; run++) runBatch(makeAccumulator)
  return ((performance.now() - start) / 3).toFixed(2)
}

console.log(`Array: ${measure(() => [])} ms`)
console.log(`Set:   ${measure(() => new Set())} ms`)
'

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
mcollina merged commit a09f38d into platformatic:main Nov 6, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants