Skip to content

Commit

Permalink
refactor(core): use performance API for signals (#54521)
Browse files Browse the repository at this point in the history
This commit adds a standard performance marker that can be viewed in Chrome dev tools and other tooling.
See more info at https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark

PR Close #54521
  • Loading branch information
pkozlowski-opensource authored and dylhunn committed Feb 23, 2024
1 parent 4efcc74 commit 0d95ae5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/render3/reactivity/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import {createComputed, SIGNAL} from '@angular/core/primitives/signals';

import {performanceMarkFeature} from '../../util/performance';

import {Signal, ValueEqualityFn} from './api';

/**
Expand All @@ -24,6 +26,7 @@ export interface CreateComputedOptions<T> {
* Create a computed `Signal` which derives a reactive value from an expression.
*/
export function computed<T>(computation: () => T, options?: CreateComputedOptions<T>): Signal<T> {
performanceMarkFeature('NgSignals');
const getter = createComputed(computation);
if (options?.equal) {
getter[SIGNAL].equal = options.equal;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/render3/reactivity/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {DestroyRef} from '../../linker/destroy_ref';
import {FLAGS, LViewFlags, EFFECTS_TO_SCHEDULE} from '../interfaces/view';

import {assertNotInReactiveContext} from './asserts';
import {performanceMarkFeature} from '../../util/performance';


/**
Expand Down Expand Up @@ -240,6 +241,7 @@ export interface CreateEffectOptions {
export function effect(
effectFn: (onCleanup: EffectCleanupRegisterFn) => void,
options?: CreateEffectOptions): EffectRef {
performanceMarkFeature('NgSignals');
ngDevMode &&
assertNotInReactiveContext(
effect,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/render3/reactivity/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import {createSignal, SIGNAL, SignalGetter, SignalNode, signalSetFn, signalUpdateFn} from '@angular/core/primitives/signals';

import {performanceMarkFeature} from '../../util/performance';

import {isSignal, Signal, ValueEqualityFn} from './api';

/** Symbol used distinguish `WritableSignal` from other non-writable signals and functions. */
Expand Down Expand Up @@ -63,6 +65,7 @@ export interface CreateSignalOptions<T> {
* Create a `Signal` that can be set or updated directly.
*/
export function signal<T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T> {
performanceMarkFeature('NgSignals');
const signalFn = createSignal(initialValue) as SignalGetter<T>& WritableSignal<T>;
const node = signalFn[SIGNAL];
if (options?.equal) {
Expand Down

0 comments on commit 0d95ae5

Please sign in to comment.