LearnNewsExamplesServices
Frontmatter
id7002
titleRefactor: Move `core.Config` Defaults to Prototype
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 9, 2025, 7:34 PM
updatedAtJul 10, 2025, 2:02 PM
githubUrlhttps://github.com/neomjs/neo/issues/7002
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 10, 2025, 2:02 PM

Refactor: Move core.Config Defaults to Prototype

Closed v10.0.0-beta.6 enhancement
tobiu
tobiu commented on Jul 9, 2025, 7:34 PM

Problem

The Neo.core.Config class currently assigns default values for clone, cloneOnGet, isEqual, and mergeStrategy directly on each instance within its constructor or through class field initializers.

In a large-scale application, there can be tens of thousands of Config instances. Assigning these properties to every instance, even when they hold default values, leads to significant and unnecessary memory consumption. Each instance stores its own copy of the property keys and pointers to the values, creating considerable overhead.

Solution

To optimize memory usage and instantiation performance, we will refactor the Config class to leverage JavaScript's prototype chain.

  1. Define Defaults on Prototype: The default values for clone, cloneOnGet, isEqual, and mergeStrategy will be defined once on Neo.core.Config.prototype.

  2. Conditional Instance Assignment: The initDescriptor method will be modified to only set a property on the instance (this) if a config descriptor provides a value that is different from the prototype's default.

Benefits

  • Reduced Memory Footprint: Instances will no longer store properties for default values. The memory overhead will be near-zero for the vast majority of configs that use the defaults.
  • Faster Instantiation: The Config constructor will perform less work, leading to faster object creation, which is beneficial when creating many components dynamically.

This is a standard JavaScript optimization that is critical for the performance of a core framework component like Config.

tobiu assigned to @tobiu on Jul 9, 2025, 7:34 PM
tobiu added the enhancement label on Jul 9, 2025, 7:34 PM
tobiu referenced in commit 45e8800 - "Refactor: Move core.Config Defaults to Prototype #7002" on Jul 9, 2025, 7:52 PM
tobiu closed this issue on Jul 10, 2025, 2:02 PM