Skip to content

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

@tobiu

Description

@tobiu

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.

Metadata

Metadata

Assignees

Labels

aicoreCore framework functionalityenhancementNew feature or requestperformancePerformance improvements and optimizations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions