feat(common): use the hotspot function provided by the ArkWeb JS engine to optimize the execution of defineProperties function in the common adaptation layer (#3530)

This commit is contained in:
ajaxzheng 2025-06-24 15:25:50 +08:00 committed by GitHub
parent a602aa5653
commit 66910344ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 124 additions and 113 deletions

View File

@ -0,0 +1,52 @@
interface ILongque {
/**
* Harmony API version.
*
* @since 1
*/
version: number
/**
* Create a delegate object for `underlyingObject` or make the `initObject` a delegate for `underlyingObject`.
*
* @param underlyingObject The underlying object to be delegated.
* @param initObject Optional initial delegate object.
* @param propertyFilterFlags Optional property filter flags, must use predefined filter flags.
* @return If no error throwed, returns the new created delegate object or the `initObject`.
*
* @since 1
*/
createDelegate: (underlyingObject: object, initObject?: object, propertyFilterFlags?: number) => object
/**
* The filter flag for `createDelegate`, skip all properties in prototype chain of `underlyingObject`.
*
* @since 1
*/
SKIP_PROTOTYPE_CHAIN: 1
/**
* The filter flag for `createDelegate`, skip all properties that starts with '_'.
*
* @since 1
*/
SKIP_PREFIX_UNDERSCORE: 2
/**
* The filter flag for `createDelegate`, skip all properties that starts with '$'.
*
* @since 1
*/
SKIP_PREFIX_DOLLAR: 4
/**
* The filter flag for `createDelegate`, skip the 'constructor' property.
*
* @since 1
*/
SKIP_CONSTRUCTOR: 8
}
interface Window {
__Longque__: ILongque
}

View File

@ -0,0 +1,4 @@
// 龙雀: ArkWeb JS引擎名称
const __TINY__ = typeof window === 'undefined' ? null : window.__Longque__
export { __TINY__ }

View File

@ -13,6 +13,7 @@ import Vue from 'vue'
import * as hooks from 'vue'
import { emitter, bindFilter, getElementCssClass, getElementStatusClass } from '../utils'
import teleport from '../teleport'
import { __TINY__ } from '../__longque__'
const Teleport = teleport(hooks)
@ -183,8 +184,8 @@ const generateChildren = ($children) => {
return children
}
const defineProperties = (vm, instance, filter) => {
for (let name in instance) {
const originalDefineProperties = (vm, instance, filter) => {
for (const name in instance) {
if (typeof filter === 'function' && filter(name)) continue
Object.defineProperty(vm, name, {
@ -198,6 +199,13 @@ const defineProperties = (vm, instance, filter) => {
return vm
}
const harmonyDefineProperties = (vm, instance) => {
const propertyFilterFlags = __TINY__.SKIP_PREFIX_UNDERSCORE | __TINY__.SKIP_PREFIX_DOLLAR | __TINY__.SKIP_CONSTRUCTOR
__TINY__.createDelegate(instance, vm, propertyFilterFlags)
}
const defineProperties = __TINY__ ? harmonyDefineProperties : originalDefineProperties
const filter = (name) => name.indexOf('$') === 0 || name.indexOf('_') === 0 || name === 'constructor'
const createVm = (vm, instance, context = undefined) => {

View File

@ -3,6 +3,7 @@ import * as compositionHooks from '@vue/composition-api'
import * as vueHooks from 'vue'
import { bindFilter, emitter, getElementCssClass, getElementStatusClass } from '../utils'
import teleport from '../teleport'
import { __TINY__ } from '../__longque__'
// vue2.7有version字段
const isVueHooks = Boolean(Vue.version?.includes('2.7'))
@ -179,7 +180,7 @@ const generateChildren = ($children) => {
return children
}
const defineProperties = (vm, instance, filter) => {
const originalDefineProperties = (vm, instance, filter) => {
for (const name in instance) {
if (typeof filter === 'function' && filter(name)) continue
@ -194,6 +195,13 @@ const defineProperties = (vm, instance, filter) => {
return vm
}
const harmonyDefineProperties = (vm, instance) => {
const propertyFilterFlags = __TINY__.SKIP_PREFIX_UNDERSCORE | __TINY__.SKIP_PREFIX_DOLLAR | __TINY__.SKIP_CONSTRUCTOR
__TINY__.createDelegate(instance, vm, propertyFilterFlags)
}
const defineProperties = __TINY__ ? harmonyDefineProperties : originalDefineProperties
const filter = (name) => name.indexOf('$') === 0 || name.indexOf('_') === 0 || name === 'constructor'
const createVm = (vm, instance, context = undefined) => {

View File

@ -13,6 +13,7 @@ import * as hooks from 'vue'
import { camelize, capitalize, hyphenate } from '@opentiny/utils'
import { bindFilter, emitter, getElementCssClass, getElementStatusClass } from '../utils'
import { __TINY__ } from '../__longque__'
const Teleport = hooks.Teleport
@ -233,7 +234,7 @@ const generateChildren = (subTree) => {
return children
}
const defineProperties = (vm, instance, property, filter) => {
const originalDefineProperties = (vm, instance, property, filter) => {
for (const name in instance[property]) {
if (typeof filter === 'function' && filter(name)) continue
@ -248,11 +249,18 @@ const defineProperties = (vm, instance, property, filter) => {
return vm
}
const harmonyDefineProperties = (vm, instance, property) => {
const propertyFilterFlags = __TINY__.SKIP_PREFIX_UNDERSCORE
__TINY__.createDelegate(instance[property], vm, propertyFilterFlags)
}
const defineProperties = __TINY__ ? harmonyDefineProperties : originalDefineProperties
const filter = (name) => name.indexOf('_') === 0
const defineInstanceVm = (vm, instance) => {
defineProperties(vm, instance, 'setupState', null)
defineProperties(vm, instance, 'props', filter)
originalDefineProperties(vm, instance, 'setupState', null)
originalDefineProperties(vm, instance, 'props', filter)
defineProperties(vm, instance, 'ctx', filter)
return vm

View File

@ -5,36 +5,16 @@
"noImplicitAny": false,
"baseUrl": ".",
"paths": {
"@opentiny/vue-huicharts-amap": [
"packages/vue/src/chart/autonavi-map"
],
"@opentiny/vue-huicharts-bmap": [
"packages/vue/src/chart/baidu-map"
],
"@opentiny/vue-huicharts-*": [
"packages/vue/src/chart/chart-*"
],
"@opentiny/vue-*": [
"packages/vue-*",
"packages/vue/src/*"
],
"@opentiny/vue-renderless/types*": [
"packages/renderless/types*"
],
"@opentiny/vue-renderless*": [
"packages/renderless/src*"
],
"virtual:common/adapter/vue": [
"packages/vue-common/src/adapter/vue2.7/index.ts"
],
"virtual:locale/vue": [
"packages/vue-locale/src/vue2.7/index.ts"
]
"@opentiny/vue-huicharts-amap": ["packages/vue/src/chart/autonavi-map"],
"@opentiny/vue-huicharts-bmap": ["packages/vue/src/chart/baidu-map"],
"@opentiny/vue-huicharts-*": ["packages/vue/src/chart/chart-*"],
"@opentiny/vue-*": ["packages/vue-*", "packages/vue/src/*"],
"@opentiny/vue-renderless/types*": ["packages/renderless/types*"],
"@opentiny/vue-renderless*": ["packages/renderless/src*"],
"virtual:common/adapter/vue": ["packages/vue-common/src/adapter/vue2.7/index.ts"],
"virtual:locale/vue": ["packages/vue-locale/src/vue2.7/index.ts"]
},
"types": [
"node",
"vite/client"
]
"types": ["node", "vite/client"]
},
"vueCompilerOptions": {
"target": 2.7
@ -44,11 +24,8 @@
"packages/**/*.tsx",
"packages/**/*.vue",
"examples/vue2.7/shims-app.d.ts",
"examples/vue2.7/shims-vue.d.ts"
"examples/vue2.7/shims-vue.d.ts",
"packages/vue-common/src/__longque__.d.ts"
],
"exclude": [
"**/node_modules",
"**/dist*",
"**/*.md"
]
}
"exclude": ["**/node_modules", "**/dist*", "**/*.md"]
}

View File

@ -5,36 +5,16 @@
"noImplicitAny": false,
"baseUrl": ".",
"paths": {
"@opentiny/vue-huicharts-amap": [
"packages/vue/src/chart/autonavi-map"
],
"@opentiny/vue-huicharts-bmap": [
"packages/vue/src/chart/baidu-map"
],
"@opentiny/vue-huicharts-*": [
"packages/vue/src/chart/chart-*"
],
"@opentiny/vue-*": [
"packages/vue-*",
"packages/vue/src/*"
],
"@opentiny/vue-renderless/types*": [
"packages/renderless/types*"
],
"@opentiny/vue-renderless*": [
"packages/renderless/src*"
],
"virtual:common/adapter/vue": [
"packages/vue-common/src/adapter/vue2/index.ts"
],
"virtual:locale/vue": [
"packages/vue-locale/src/vue2/index.ts"
]
"@opentiny/vue-huicharts-amap": ["packages/vue/src/chart/autonavi-map"],
"@opentiny/vue-huicharts-bmap": ["packages/vue/src/chart/baidu-map"],
"@opentiny/vue-huicharts-*": ["packages/vue/src/chart/chart-*"],
"@opentiny/vue-*": ["packages/vue-*", "packages/vue/src/*"],
"@opentiny/vue-renderless/types*": ["packages/renderless/types*"],
"@opentiny/vue-renderless*": ["packages/renderless/src*"],
"virtual:common/adapter/vue": ["packages/vue-common/src/adapter/vue2/index.ts"],
"virtual:locale/vue": ["packages/vue-locale/src/vue2/index.ts"]
},
"types": [
"node",
"vite/client"
]
"types": ["node", "vite/client"]
},
"vueCompilerOptions": {
"target": 2
@ -44,11 +24,8 @@
"packages/**/*.tsx",
"packages/**/*.vue",
"examples/vue2/shims-app.d.ts",
"examples/vue2/shims-vue.d.ts"
"examples/vue2/shims-vue.d.ts",
"packages/vue-common/src/__longque__.d.ts"
],
"exclude": [
"**/node_modules",
"**/dist*",
"**/*.md"
]
}
"exclude": ["**/node_modules", "**/dist*", "**/*.md"]
}

View File

@ -5,36 +5,16 @@
"noImplicitAny": false,
"baseUrl": ".",
"paths": {
"@opentiny/vue-huicharts-amap": [
"packages/vue/src/huicharts/huicharts-amap"
],
"@opentiny/vue-huicharts-bmap": [
"packages/vue/src/huicharts/huicharts-bmap"
],
"@opentiny/vue-huicharts-*": [
"packages/vue/src/huicharts/chart-*"
],
"@opentiny/vue-*": [
"packages/vue-*",
"packages/vue/src/*"
],
"@opentiny/vue-renderless/types*": [
"packages/renderless/types*"
],
"@opentiny/vue-renderless*": [
"packages/renderless/src*"
],
"virtual:common/adapter/vue": [
"packages/vue-common/src/adapter/vue3/index.ts"
],
"virtual:locale/vue": [
"packages/vue-locale/src/vue3/index.ts"
]
"@opentiny/vue-huicharts-amap": ["packages/vue/src/huicharts/huicharts-amap"],
"@opentiny/vue-huicharts-bmap": ["packages/vue/src/huicharts/huicharts-bmap"],
"@opentiny/vue-huicharts-*": ["packages/vue/src/huicharts/chart-*"],
"@opentiny/vue-*": ["packages/vue-*", "packages/vue/src/*"],
"@opentiny/vue-renderless/types*": ["packages/renderless/types*"],
"@opentiny/vue-renderless*": ["packages/renderless/src*"],
"virtual:common/adapter/vue": ["packages/vue-common/src/adapter/vue3/index.ts"],
"virtual:locale/vue": ["packages/vue-locale/src/vue3/index.ts"]
},
"types": [
"node",
"vite/client"
]
"types": ["node", "vite/client"]
},
"vueCompilerOptions": {
"target": 3
@ -44,11 +24,8 @@
"packages/**/*.tsx",
"packages/**/*.vue",
"examples/vue3/shims-app.d.ts",
"examples/vue3/shims-vue.d.ts"
"examples/vue3/shims-vue.d.ts",
"packages/vue-common/src/__longque__.d.ts"
],
"exclude": [
"**/node_modules",
"**/dist*",
"**/*.md"
]
"exclude": ["**/node_modules", "**/dist*", "**/*.md"]
}