Skip to content

Conversation

@edison1105
Copy link
Member

No description provided.

…s using computed to prevent redundant calls.
Copilot AI review requested due to automatic review settings December 8, 2025 01:18
@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch edison/perf/props

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 85.2 kB 29.9 kB 26.4 kB
runtime-dom.global.prod.js 108 kB 40.5 kB 36.5 kB
vue.global.prod.js 166 kB 60.5 kB 53.9 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.2 kB 18.8 kB 17.2 kB
createApp 57.2 kB 22 kB 20.1 kB
createApp + vaporInteropPlugin 96 kB (+2 B) 35.4 kB (+1 B) 32 kB (+30 B)
createVaporApp 42 kB (+2 B) 15.5 kB (+1 B) 14.1 kB (-4 B)
createSSRApp 61.6 kB 23.8 kB 21.7 kB
defineCustomElement 63.3 kB 23.8 kB 21.7 kB
overall 71.9 kB 27.2 kB 24.8 kB

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 8, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@14178

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@14178

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@14178

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@14178

@vue/compiler-vapor

npm i https://pkg.pr.new/@vue/compiler-vapor@14178

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@14178

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@14178

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@14178

@vue/runtime-vapor

npm i https://pkg.pr.new/@vue/runtime-vapor@14178

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@14178

@vue/shared

npm i https://pkg.pr.new/@vue/shared@14178

vue

npm i https://pkg.pr.new/vue@14178

@vue/compat

npm i https://pkg.pr.new/@vue/compat@14178

commit: 67d0e27

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the runtime-vapor module by implementing computed-based caching for dynamic prop/attr and slot function sources to prevent redundant function calls when components access multiple props/attrs from the same v-bind source.

Key Changes:

  • Introduced resolveFunctionSource helper that wraps function sources in computed refs for automatic caching
  • Unified caching logic between props and slots by making resolveFunctionSource a shared utility
  • Added comprehensive test coverage verifying cache behavior and reactivity

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/runtime-vapor/src/componentProps.ts Added resolveFunctionSource helper with computed-based caching; updated resolveSource and all dynamic source resolution to use the new caching mechanism
packages/runtime-vapor/src/componentSlots.ts Removed duplicate resolveDynamicSlot function; now imports and uses shared resolveFunctionSource from componentProps
packages/runtime-vapor/tests/componentProps.spec.ts Added comprehensive test suite for dynamic props source caching, covering multiple access patterns, reactivity, and mixed static/dynamic scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +55
export function resolveFunctionSource<T>(
source: (() => T) & { _cache?: ComputedRef<T> },
): T {
if (!source._cache) {
source._cache = computed(source)
}
return source._cache.value
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The resolveFunctionSource function mutates the input function by attaching a _cache property. This could cause unexpected behavior if:

  1. The same function is used in multiple contexts or components - they would share the same cached computed ref
  2. Functions are dynamically created in loops or conditionals - the cache would persist even after the function is no longer needed, potentially causing memory leaks

Consider:

  • Adding a WeakMap-based cache instead of mutating the function object
  • Documenting this behavior clearly if it's intentional
  • Ensuring function sources are stable references (not recreated on each render)
Suggested change
export function resolveFunctionSource<T>(
source: (() => T) & { _cache?: ComputedRef<T> },
): T {
if (!source._cache) {
source._cache = computed(source)
}
return source._cache.value
const functionSourceCache: WeakMap<Function, ComputedRef<any>> = new WeakMap();
export function resolveFunctionSource<T>(
source: () => T,
): T {
let cache = functionSourceCache.get(source);
if (!cache) {
cache = computed(source);
functionSourceCache.set(source, cache);
}
return cache.value;

Copilot uses AI. Check for mistakes.
}

/**
* Resolve a function source with computed caching.
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The documentation comment is incomplete. It should explain:

  1. What "computed caching" means in this context
  2. That the cache is stored on the function object itself via a _cache property
  3. The implications of this approach (e.g., functions should be stable references)
  4. When the cache is invalidated (when the computed's dependencies change)

Example:

/**
 * Resolve a function source with computed caching.
 * 
 * Wraps the source function in a computed ref to cache its result.
 * The cache is stored directly on the function object via a `_cache` property,
 * so the same function reference will always use the same cache.
 * The cached value will be recomputed when the function's reactive dependencies change.
 * 
 * @param source - The function to resolve, must return a value of type T
 * @returns The cached result of calling the source function
 */
Suggested change
* Resolve a function source with computed caching.
* Resolve a function source with computed caching.
*
* Wraps the source function in a computed ref to cache its result.
* The cache is stored directly on the function object via a `_cache` property,
* so the same function reference will always use the same cache.
* The cached value will be recomputed when the function's reactive dependencies change.
* This approach requires that the function reference remains stable; if a new function
* is passed, a new cache will be created and the previous cache will not be reused.
*
* @param source - The function to resolve, must return a value of type T
* @returns The cached result of calling the source function

Copilot uses AI. Check for mistakes.
@edison1105 edison1105 merged commit 5ee8913 into minor Dec 8, 2025
23 checks passed
@edison1105 edison1105 deleted the edison/perf/props branch December 8, 2025 01:34
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