Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions benchmark/react/cases/004-various-update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
// LICENSE file in the root directory of this source tree.

import { root, useEffect, useState } from '@lynx-js/react';
import { SnapshotInstance } from '@lynx-js/react/internal';
import {
BackgroundSnapshotInstance,
SnapshotInstance,
} from '@lynx-js/react/internal';
import type { CSSProperties, MainThread, NodesRef } from '@lynx-js/types';

import { hook, isMainThread } from '../../src/hook.js';

if (__MAIN_THREAD__) {
if (typeof Codspeed !== 'undefined' && __MAIN_THREAD__) {
hook(
SnapshotInstance.prototype,
'setAttribute',
Expand Down Expand Up @@ -84,6 +87,31 @@ if (__MAIN_THREAD__) {
);
}

if (typeof Codspeed !== 'undefined' && __BACKGROUND__) {
hook(
BackgroundSnapshotInstance.prototype,
'setAttribute',
function(this: BackgroundSnapshotInstance, old, key, value) {
const values = value as unknown[];
if (
key === 'values' && values[values.length - 1] === 'stop-benchmark-true'
) {
Comment thread
hzy marked this conversation as resolved.
// we only care about the update that stops the benchmark

Codspeed.startBenchmark();
const ret = old!.call(this, key, value);
Codspeed.stopBenchmark();
Codspeed.setExecutedBenchmark(
`${__REPO_FILEPATH__}::${__webpack_chunkname__}-setAttribute__BatchedValues`,
Comment thread
hzy marked this conversation as resolved.
);
return ret;
Comment thread
hzy marked this conversation as resolved.
}

return old!.call(this, key, value);
},
);
}

function F() {
const [stopBenchmark, setStopBenchmark] = useState(false);
const [values, setValues] = useState(
Expand Down
4 changes: 1 addition & 3 deletions benchmark/react/src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ export function hook<T, K extends keyof T>(

export const PREFIX = __REPO_FILEPATH__.split('/').slice(0, -2).join('/');

export const isMainThread =
// @ts-expect-error safely check
typeof __CreatePage === 'function';
export const isMainThread = typeof __CreatePage === 'function';
Comment thread
hzy marked this conversation as resolved.
1 change: 1 addition & 0 deletions packages/react/runtime/lazy/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { sExportsReactInternal, target } from './target.js';

export const {
BackgroundSnapshotInstance,
Component,
__ComponentIsPolyfill,
__DynamicPartChildren,
Expand Down
3 changes: 2 additions & 1 deletion packages/react/runtime/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { FC } from 'react';

import './lynx.js';

import { BackgroundSnapshotInstance } from './backgroundSnapshot.js';
import { factory as factory2 } from './compat/componentIs.js';
import { useMemo } from './hooks/react.js';
import { loadLazyBundle } from './lynx/lazy-bundle.js';
Expand All @@ -17,7 +18,7 @@ import { SnapshotInstance, __page, __pageId, createSnapshot, snapshotManager } f

export { __page, __pageId, __root };

export { SnapshotInstance, snapshotCreateList, createSnapshot, snapshotManager };
export { BackgroundSnapshotInstance, SnapshotInstance, snapshotCreateList, createSnapshot, snapshotManager };

export const __DynamicPartSlot: DynamicPartType = DynamicPartType.Slot;
export const __DynamicPartMultiChildren: DynamicPartType = DynamicPartType.MultiChildren;
Expand Down
Loading