LearnNewsExamplesServices
Frontmatter
id9336
titlePerformance: Optimize core utilities in Neo.mjs (cloneMap, camel, loops)
stateClosed
labels
enhancementaiperformancecore
assigneestobiu
createdAtFeb 27, 2026, 6:44 PM
updatedAtFeb 27, 2026, 6:45 PM
githubUrlhttps://github.com/neomjs/neo/issues/9336
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtFeb 27, 2026, 6:45 PM

Performance: Optimize core utilities in Neo.mjs (cloneMap, camel, loops)

Closed v12.0.0/archive-v12-0-0-chunk-5 enhancementaiperformancecore
tobiu
tobiu commented on Feb 27, 2026, 6:44 PM

Problem

Several utility methods in src/Neo.mjs that are part of extremely hot paths (called thousands of times during initialization and config parsing) were using slightly unoptimized patterns. These included .forEach callbacks, unnecessary regex executions for strings without dashes, and arrow functions in type detection maps.

Solution

Implemented a series of micro-optimizations in src/Neo.mjs:

  1. cloneMap.Object: Replaced Reflect.ownKeys(obj).forEach(...) with a for...of loop to eliminate closure execution overhead while safely maintaining non-enumerable symbol cloning.
  2. camel(value): Added an if (!value.includes('-')) return value; fast-path to bypass the regex engine for pre-camel-cased or normal strings.
  3. assignDefaults & applyFromNs: Replaced Object.entries().forEach(...) with for...in loops, avoiding array allocation and closure overheads.
  4. typeDetector: Converted arrow functions to standard method definitions to help V8 optimize the functions without lexical this binding overhead.
tobiu
tobiu Feb 27, 2026, 6:45 PM

Input from Gemini 3.1 Pro:

✦ Resolved in the linked commit.

  • Replaced forEach loops with for...of and for...in in cloneMap.Object, assignDefaults, and applyFromNs.
  • Added an early return fast-path to camel().
  • Changed typeDetector arrow functions to standard methods for better V8 engine optimization.