Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cache to defineGetter #6042

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nigrosimone
Copy link

@nigrosimone nigrosimone commented Oct 12, 2024

Adding this cache to the defineGetter function has several implications:

  • Performance Improvement: The getter function will only be called once, and its result will be stored. Subsequent accesses to the property will return the cached value, avoiding the cost of repeatedly executing the getter function.
  • Consistency: The value returned by the getter will remain consistent for the lifetime of the property on the object. If the getter logic involves any computation that could potentially change, this cache will prevent any changes from being reflected in the property's value after the first access.
  • Side Effects: If the getter function has side effects (e.g., logging, triggering other operations), these will only occur once when the value is first computed. Subsequent accesses will not trigger these side effects.

Just for POC, I have enabled only on query

Adding this cache to the defineGetter function has several implications:

Performance Improvement: The getter function will only be called once, and its result will be stored. Subsequent accesses to the property will return the cached value, avoiding the cost of repeatedly executing the getter function.

Consistency: The value returned by the getter will remain consistent for the lifetime of the property on the object. If the getter logic involves any computation that could potentially change, this cache will prevent any changes from being reflected in the property's value after the first access.

Side Effects: If the getter function has side effects (e.g., logging, triggering other operations), these will only occur once when the value is first computed. Subsequent accesses will not trigger these side effects.
@IamLizu
Copy link
Member

IamLizu commented Jan 15, 2025

Referencing expressjs/discussions#306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants