Implement a basic benchmark test, and deprecate derivation.map()/flatMap()

This starts a new workspace at `packages/benchmarks` where future benchmarks
are going to sit. For now, it only contains a basic profile of a `sequence.play()`
setup.

It also removes all uses of `AbstractDerivation.map()/flatMap()` and uses prisms
instead.
This commit is contained in:
Aria Minaei 2022-11-26 15:00:14 +01:00
parent 45b548660c
commit ae8be59366
26 changed files with 37584 additions and 56 deletions

View file

@ -9,6 +9,7 @@
{"path": "../../theatre"},
{"path": "../../packages/dataverse"},
{"path": "../../packages/playground"},
{"path": "../../packages/benchmarks"},
{"path": "../../packages/r3f"},
{"path": "../../examples/basic-dom"}
]

View file

@ -10,6 +10,7 @@
],
"scripts": {
"playground": "yarn workspace playground run serve",
"benchmarks": "yarn workspace benchmarks run serve",
"test:e2e": "yarn workspace playground run test",
"test:e2e:ci": "yarn workspace playground run test:ci",
"typecheck": "yarn run build:ts",

1
packages/benchmarks/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/dist

203
packages/benchmarks/LICENSE Normal file
View file

@ -0,0 +1,203 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -0,0 +1,29 @@
import path from 'path'
import {definedGlobals} from '../../../theatre/devEnv/definedGlobals'
const benchmarksDir = path.join(__dirname, '..')
const port = 8087
const allEnvs = {
'0.5.0': () => {},
}
require('esbuild')
.serve(
{
port,
servedir: path.join(benchmarksDir, 'src'),
},
{
entryPoints: [path.join(benchmarksDir, 'src/index.tsx')],
target: ['firefox88'],
loader: {'.png': 'file', '.glb': 'file', '.svg': 'dataurl'},
bundle: true,
sourcemap: true,
define: definedGlobals,
},
)
.then((server: unknown) => {
console.log('serving', 'http://localhost:' + port)
})

View file

@ -0,0 +1,30 @@
{
"name": "benchmarks",
"version": "1.0.0-dev",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*"
],
"scripts": {
"serve": "node -r esbuild-register devEnv/serveBenchmarks.ts",
"typecheck": "yarn run build",
"build": "tsc --build ./tsconfig.json"
},
"devDependencies": {
"@theatre/core": "workspace:*",
"@theatre/core-0.5.0": "npm:@theatre/core@0.5.0",
"@theatre/dataverse-0.5.0": "npm:@theatre/dataverse@0.5.0",
"@theatre/r3f": "workspace:*",
"@theatre/studio": "workspace:*",
"@theatre/studio-0.5.0": "npm:@theatre/studio@0.5.0",
"@types/jest": "^29.2.3",
"@types/lodash-es": "^4.17.6",
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"esbuild": "^0.15.15",
"esbuild-register": "^3.4.1",
"typescript": "4.6.x"
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
declare module '*.png' {
export default string
}
declare module '*.json' {
export default {}
}
declare module '*.glb' {
export default string
}

View file

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Benchmarks Theatre.js</title>
<style>
body {
margin: 0;
padding: 0;
height: 100%;
background-color: #1a1a1a;
}
</style>
</head>
<body>
<div id="root"></div>
<script src="./index.js"></script>
</body>
</html>

View file

@ -0,0 +1,111 @@
// import studio from '@theatre/studio'
import {getProject} from '@theatre/core'
import type {
UnknownShorthandCompoundProps,
ISheet,
ISheetObject,
} from '@theatre/core'
// @ts-ignore
import benchProject1State from './Bench project 1.theatre-project-state.json'
import {Ticker} from '@theatre/dataverse'
import {setCoreTicker} from '@theatre/core/coreTicker'
const ticker = new Ticker()
setCoreTicker(ticker)
// studio.initialize({})
/**
* This test will create a project with `numberOfInstances` instances of the same sheet. Each instance
* will have a single object, and that object will have a bunch of props (see `CONFIG.depthOfProps` and `CONFIG.leavePropsAtEachBranch`).
* All of those props have been set to be sequenced in `./Bench project 1.theatre-project-state.json`.
* The test will then play the sequence from the beginning to the end, split into `CONFIG.numberOfIterations` iterations.
* We then measure the time it takes to play the sequence through.
*/
async function test1() {
const project = getProject('Bench project 1', {state: benchProject1State})
const CONFIG = {
numberOfInstances: 20,
depthOfProps: 4,
leavePropsAtEachBranch: 4,
sequenceLength: 10, // seconds
numberOfIterations: 20,
}
function getObjConf(
depth: number,
count: number,
): UnknownShorthandCompoundProps | 0 {
if (depth === 0) {
return 0
}
return Object.fromEntries(
new Array(count)
.fill(0)
.map((_, i) => [String(i), getObjConf(depth - 1, count)]),
)
}
const rootConf = getObjConf(
CONFIG.depthOfProps,
CONFIG.leavePropsAtEachBranch,
) as UnknownShorthandCompoundProps
const sheets: Array<ISheet> = []
const objects: Array<ISheetObject> = []
for (let i = 0; i < CONFIG.numberOfInstances; i++) {
const sheet = project.sheet(`Sheet`, `Instance ${i}`)
sheets.push(sheet)
const obj = sheet.object(`Obj`, rootConf)
objects.push(obj)
}
let onChangeEventsFired = 0
function subscribeToAllObjects() {
const startTime = performance.now()
for (const obj of objects) {
obj.onValuesChange((v) => {
onChangeEventsFired++
})
}
const endTime = performance.now()
console.log(
`Subscribing to ${objects.length} objects took ${endTime - startTime}ms`,
)
}
function iterateOnSequence() {
ticker.tick()
const startTime = performance.now()
for (let i = 1; i < CONFIG.numberOfIterations; i++) {
onChangeEventsFired = 0
const pos = (i / CONFIG.numberOfIterations) * CONFIG.sequenceLength
for (const sheet of sheets) {
sheet.sequence.position = pos
}
ticker.tick()
if (onChangeEventsFired !== objects.length) {
console.info(
`Expected ${objects.length} onChange events, got ${onChangeEventsFired}`,
)
}
}
const endTime = performance.now()
console.log(
`Scrubbing the sequence in ${CONFIG.numberOfIterations} iterations took ${
endTime - startTime
}ms`,
)
}
subscribeToAllObjects()
iterateOnSequence()
}
test1().then(() => {
console.log('test1 done')
})

View file

@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"rootDir": ".",
"types": ["jest", "node"],
"emitDeclarationOnly": false,
"composite": true,
"resolveJsonModule": true
},
"references": [
{"path": "../../theatre"},
{"path": "../dataverse"},
{"path": "../r3f"}
],
"include": ["./src/**/*", "./devEnv/**/*"]
}

View file

@ -1,10 +1,11 @@
import type {IdentityDerivationProvider} from './Atom'
import {val} from './Atom'
import type {Pointer} from './pointer'
import pointer from './pointer'
import type {IBox} from './Box'
import Box from './Box'
import type {$FixMe, $IntentionalAny} from './types'
import {valueDerivation} from './Atom'
import prism from './derivations/prism/prism'
/**
* Allows creating pointer-derivations where the pointer can be switched out.
@ -48,12 +49,13 @@ export default class PointerProxy<O extends {}>
* @param path - The path to create the derivation at.
*/
getIdentityDerivation(path: Array<string | number>) {
return this._currentPointerBox.derivation.flatMap((p) => {
return prism(() => {
const currentPointer = this._currentPointerBox.derivation.getValue()
const subPointer = path.reduce(
(pointerSoFar, pathItem) => (pointerSoFar as $IntentionalAny)[pathItem],
p,
currentPointer,
)
return valueDerivation(subPointer)
return val(subPointer)
})
}
}

View file

@ -251,10 +251,9 @@ export default abstract class AbstractDerivation<V> implements IDerivation<V> {
protected _becomeCold() {}
/**
* Creates a new derivation from this derivation using the provided mapping function. The new derivation's value will be
* `fn(thisDerivation.getValue())`.
* A simple mapping function similar to Array.map()
*
* @param fn - The mapping function to use. Note: it accepts a plain value, not a derivation.
* @deprecated This is a remnant of the old monadic api. Now it's functionally equal to `prism(() => fn(der.getValue()))`, so use that instead.
*/
map<T>(fn: (v: V) => T): IDerivation<T> {
return map(this, fn)
@ -264,6 +263,8 @@ export default abstract class AbstractDerivation<V> implements IDerivation<V> {
* Same as {@link AbstractDerivation.map}, but the mapping function can also return a derivation, in which case the derivation returned
* by `flatMap` takes the value of that derivation.
*
* @deprecated This is a remnant of the old monadic api. Now it's functionally equal to `prism(() => val(fn(val(der))))`
*
* @example
* ```ts
* // Simply using map() here would return the inner derivation when we call getValue()

View file

@ -21,7 +21,7 @@ const makeMapDerivationClass = () =>
let cls: ReturnType<typeof makeMapDerivationClass> | undefined = undefined
export default function flatMap<V, R>(
export default function map<V, R>(
dep: IDerivation<V>,
fn: (v: V) => R,
): IDerivation<R> {

View file

@ -4,7 +4,6 @@
import Atom, {val} from '../../Atom'
import Ticker from '../../Ticker'
import type {$FixMe, $IntentionalAny} from '../../types'
import ConstantDerivation from '../ConstantDerivation'
import iterateAndCountTicks from '../iterateAndCountTicks'
import prism, {PrismDerivation} from './prism'
@ -31,8 +30,8 @@ describe('prism', () => {
expect(changes).toMatchObject(['foo2boo'])
})
it('should only collect immediate dependencies', () => {
const aD = new ConstantDerivation(1)
const bD = aD.map((v) => v * 2)
const aD = prism(() => 1)
const bD = prism(() => aD.getValue() * 2)
const cD = prism(() => {
return bD.getValue()
})

View file

@ -12,9 +12,9 @@ import type {PointerType} from '@theatre/dataverse'
import {isPointer} from '@theatre/dataverse'
import {isDerivation, valueDerivation} from '@theatre/dataverse'
import type {$IntentionalAny, VoidFn} from '@theatre/shared/utils/types'
import coreTicker from './coreTicker'
import type {ProjectId} from '@theatre/shared/utils/ids'
import {_coreLogger} from './_coreLogger'
import {getCoreTicker} from './coreTicker'
export {notify} from '@theatre/shared/notify'
export {types}
@ -156,9 +156,9 @@ export function onChange<P extends PointerType<$IntentionalAny>>(
): VoidFn {
if (isPointer(pointer)) {
const derivation = valueDerivation(pointer)
return derivation.tapImmediate(coreTicker, callback as $IntentionalAny)
return derivation.tapImmediate(getCoreTicker(), callback as $IntentionalAny)
} else if (isDerivation(pointer)) {
return pointer.tapImmediate(coreTicker, callback as $IntentionalAny)
return pointer.tapImmediate(getCoreTicker(), callback as $IntentionalAny)
} else {
throw new Error(
`Called onChange(p) where p is neither a pointer nor a derivation.`,

View file

@ -1,5 +1,17 @@
import {Ticker} from '@theatre/dataverse'
const coreTicker = Ticker.raf
let coreTicker: Ticker
export default coreTicker
export function setCoreTicker(ticker: Ticker) {
if (coreTicker) {
throw new Error(`coreTicker is already set`)
}
coreTicker = ticker
}
export function getCoreTicker(): Ticker {
if (!coreTicker) {
coreTicker = Ticker.raf
}
return coreTicker
}

View file

@ -1,12 +1,11 @@
import type Project from '@theatre/core/projects/Project'
import coreTicker from '@theatre/core/coreTicker'
import type Sheet from '@theatre/core/sheets/Sheet'
import type {SequenceAddress} from '@theatre/shared/utils/addresses'
import didYouMean from '@theatre/shared/utils/didYouMean'
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
import type {IBox, IDerivation, Pointer} from '@theatre/dataverse'
import {pointer} from '@theatre/dataverse'
import {Box, prism, val, valueDerivation} from '@theatre/dataverse'
import {Box, prism, val} from '@theatre/dataverse'
import {padStart} from 'lodash-es'
import type {
IPlaybackController,
@ -17,6 +16,7 @@ import TheatreSequence from './TheatreSequence'
import type {ILogger} from '@theatre/shared/logger'
import type {ISequence} from '..'
import {notify} from '@theatre/shared/notify'
import {getCoreTicker} from '@theatre/core/coreTicker'
export type IPlaybackRange = [from: number, to: number]
@ -63,20 +63,22 @@ export default class Sequence {
this.publicApi = new TheatreSequence(this)
this._playbackControllerBox = new Box(
playbackController ?? new DefaultPlaybackController(coreTicker),
playbackController ?? new DefaultPlaybackController(getCoreTicker()),
)
this._statePointerDerivation = this._playbackControllerBox.derivation.map(
(playbackController) => playbackController.statePointer,
this._statePointerDerivation = prism(
() => this._playbackControllerBox.derivation.getValue().statePointer,
)
this._positionD = this._statePointerDerivation.flatMap((statePointer) =>
valueDerivation(statePointer.position),
)
this._positionD = prism(() => {
const statePointer = this._statePointerDerivation.getValue()
return val(statePointer.position)
})
this._positionFormatterD = this._subUnitsPerUnitD.map(
(subUnitsPerUnit) => new TimeBasedPositionFormatter(subUnitsPerUnit),
)
this._positionFormatterD = prism(() => {
const subUnitsPerUnit = val(this._subUnitsPerUnitD)
return new TimeBasedPositionFormatter(subUnitsPerUnit)
})
}
getIdentityDerivation(path: Array<string | number>): IDerivation<unknown> {

View file

@ -3,7 +3,7 @@ import {defer} from '@theatre/shared/utils/defer'
import type Sequence from './Sequence'
import type {IPlaybackDirection, IPlaybackRange} from './Sequence'
import AudioPlaybackController from './playbackControllers/AudioPlaybackController'
import coreTicker from '@theatre/core/coreTicker'
import {getCoreTicker} from '@theatre/core/coreTicker'
import type {Pointer} from '@theatre/dataverse'
import {notify} from '@theatre/shared/notify'
@ -289,7 +289,7 @@ export default class TheatreSequence implements ISequence {
await resolveAudioBuffer(args)
const playbackController = new AudioPlaybackController(
coreTicker,
getCoreTicker(),
decodedBuffer,
audioContext,
gainNode,

View file

@ -4,7 +4,7 @@ import type {
TrackData,
} from '@theatre/core/projects/store/types/SheetState_Historic'
import type {IDerivation, Pointer} from '@theatre/dataverse'
import {ConstantDerivation, prism, val} from '@theatre/dataverse'
import {prism, val} from '@theatre/dataverse'
import type {IUtilContext} from '@theatre/shared/logger'
import type {SerializableValue} from '@theatre/shared/utils/types'
import UnitBezier from 'timing-function/lib/UnitBezier'
@ -36,12 +36,12 @@ export default function interpolationTripleAtPosition(
'driver',
() => {
if (!track) {
return new ConstantDerivation(undefined)
return prism(() => undefined)
} else if (track.type === 'BasicKeyframedTrack') {
return _forKeyframedTrack(ctx, track, timeD)
} else {
ctx.logger.error(`Track type not yet supported.`)
return new ConstantDerivation(undefined)
return prism(() => undefined)
}
},
[track],
@ -79,7 +79,7 @@ function _forKeyframedTrack(
})
}
const undefinedConstD = new ConstantDerivation(undefined)
const undefinedConstD = prism(() => undefined)
function updateState(
ctx: IUtilContext,
@ -159,7 +159,7 @@ const states = {
started: true,
validFrom: -Infinity,
validTo: kf.position,
der: new ConstantDerivation({left: kf.value, progression: 0}),
der: prism(() => ({left: kf.value, progression: 0})),
}
},
lastKeyframe(kf: Keyframe): IStartedState {
@ -167,7 +167,7 @@ const states = {
started: true,
validFrom: kf.position,
validTo: Infinity,
der: new ConstantDerivation({left: kf.value, progression: 0}),
der: prism(() => ({left: kf.value, progression: 0})),
}
},
between(
@ -180,7 +180,7 @@ const states = {
started: true,
validFrom: left.position,
validTo: right.position,
der: new ConstantDerivation({left: left.value, progression: 0}),
der: prism(() => ({left: left.value, progression: 0})),
}
}

View file

@ -228,7 +228,8 @@ export default class SheetObjectTemplate {
*/
getMapOfValidSequenceTracks_forStudio(): IDerivation<IPropPathToTrackIdTree> {
return this._cache.get('getMapOfValidSequenceTracks_forStudio', () =>
this.getArrayOfValidSequenceTracks().map((arr) => {
prism(() => {
const arr = val(this.getArrayOfValidSequenceTracks())
let map = {}
for (const {pathToProp, trackId} of arr) {

View file

@ -1,6 +1,6 @@
import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
import type {IProject} from '@theatre/core/projects/TheatreProject'
import coreTicker from '@theatre/core/coreTicker'
import {getCoreTicker} from '@theatre/core/coreTicker'
import type {ISheet} from '@theatre/core/sheets/TheatreSheet'
import type {SheetObjectAddress} from '@theatre/shared/utils/addresses'
import SimpleCache from '@theatre/shared/utils/SimpleCache'
@ -158,7 +158,7 @@ export default class TheatreSheetObject<
}
onValuesChange(fn: (values: this['value']) => void): VoidFn {
return this._valuesDerivation().tapImmediate(coreTicker, fn)
return this._valuesDerivation().tapImmediate(getCoreTicker(), fn)
}
// internal: Make the deviration keepHot if directly read

View file

@ -7,7 +7,7 @@ import type {
} from '@theatre/core/sheets/TheatreSheet'
import TheatreSheet from '@theatre/core/sheets/TheatreSheet'
import type {SheetAddress} from '@theatre/shared/utils/addresses'
import {Atom, valueDerivation} from '@theatre/dataverse'
import {Atom, prism, val} from '@theatre/dataverse'
import type SheetTemplate from './SheetTemplate'
import type {ObjectAddressKey, SheetInstanceId} from '@theatre/shared/utils/ids'
import type {StrictRecord} from '@theatre/shared/utils/types'
@ -88,15 +88,21 @@ export default class Sheet {
getSequence(): Sequence {
if (!this._sequence) {
const lengthD = valueDerivation(
this.project.pointers.historic.sheetsById[this.address.sheetId].sequence
.length,
).map(sanitizeSequenceLength)
const lengthD = prism(() => {
const unsanitized = val(
this.project.pointers.historic.sheetsById[this.address.sheetId]
.sequence.length,
)
return sanitizeSequenceLength(unsanitized)
})
const subUnitsPerUnitD = valueDerivation(
this.project.pointers.historic.sheetsById[this.address.sheetId].sequence
.subUnitsPerUnit,
).map(sanitizeSequenceSubUnitsPerUnit)
const subUnitsPerUnitD = prism(() => {
const unsanitized = val(
this.project.pointers.historic.sheetsById[this.address.sheetId]
.sequence.subUnitsPerUnit,
)
return sanitizeSequenceSubUnitsPerUnit(unsanitized)
})
this._sequence = new Sequence(
this.template.project,

View file

@ -6,7 +6,7 @@ import type {ProjectState_Historic} from '@theatre/core/projects/store/storeType
import type {SheetState_Historic} from '@theatre/core/projects/store/types/SheetState_Historic'
import * as t from '@theatre/core/propTypes'
import getStudio from '@theatre/studio/getStudio'
import coreTicker from '@theatre/core/coreTicker'
import {getCoreTicker} from '@theatre/core/coreTicker'
import globals from './globals'
import type {SheetId} from './utils/ids'
/* eslint-enable no-restricted-syntax */
@ -42,7 +42,7 @@ export async function setupTestSheet(sheetState: SheetState_Historic) {
state: projectState,
})
const ticker = coreTicker
const ticker = getCoreTicker()
ticker.tick()
await project.ready

View file

@ -109,7 +109,7 @@ export default function useKeyboardShortcuts() {
)
const playbackPromise = seq.playDynamicRange(
controlledPlaybackStateD.map(({range}) => range),
prism(() => val(controlledPlaybackStateD).range),
)
const playbackStateBox = getPlaybackStateBox(seq)

327
yarn.lock
View file

@ -5938,6 +5938,13 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/android-arm@npm:0.15.15":
version: 0.15.15
resolution: "@esbuild/android-arm@npm:0.15.15"
conditions: os=android & cpu=arm
languageName: node
linkType: hard
"@esbuild/android-arm@npm:0.16.7":
version: 0.16.7
resolution: "@esbuild/android-arm@npm:0.16.7"
@ -6001,6 +6008,13 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-loong64@npm:0.15.15":
version: 0.15.15
resolution: "@esbuild/linux-loong64@npm:0.15.15"
conditions: os=linux & cpu=loong64
languageName: node
linkType: hard
"@esbuild/linux-loong64@npm:0.16.7":
version: 0.16.7
resolution: "@esbuild/linux-loong64@npm:0.16.7"
@ -8109,6 +8123,15 @@ __metadata:
languageName: unknown
linkType: soft
"@theatre/core-0.5.0@npm:@theatre/core@0.5.0":
version: 0.5.0
resolution: "@theatre/core@npm:0.5.0"
dependencies:
"@theatre/dataverse": 0.5.0
checksum: a2ea19d31f2574b5222f4dca5dc5f75c5a63f7d9b2ef27b185698b6617193bac6aaf2780215e32aad92bf208791703040a3f3c0cf51017f640a36d44d2dfab70
languageName: node
linkType: hard
"@theatre/core@workspace:*, @theatre/core@workspace:theatre/core":
version: 0.0.0-use.local
resolution: "@theatre/core@workspace:theatre/core"
@ -8117,6 +8140,15 @@ __metadata:
languageName: unknown
linkType: soft
"@theatre/dataverse-0.5.0@npm:@theatre/dataverse@0.5.0, @theatre/dataverse@npm:0.5.0":
version: 0.5.0
resolution: "@theatre/dataverse@npm:0.5.0"
dependencies:
lodash-es: ^4.17.21
checksum: a7dcd31539ecaaabb054f298f06340cf5e1958cacb97d36ae9ac92c36d43366ac0cb0a2e48502e4fd870947489f764179d7f99f4d6ca1f19920f360393c75781
languageName: node
linkType: hard
"@theatre/dataverse-experiments@workspace:packages/dataverse-experiments":
version: 0.0.0-use.local
resolution: "@theatre/dataverse-experiments@workspace:packages/dataverse-experiments"
@ -8212,6 +8244,17 @@ __metadata:
languageName: unknown
linkType: soft
"@theatre/studio-0.5.0@npm:@theatre/studio@0.5.0":
version: 0.5.0
resolution: "@theatre/studio@npm:0.5.0"
dependencies:
"@theatre/dataverse": 0.5.0
peerDependencies:
"@theatre/core": "*"
checksum: a7c11054df8094b375cdfaba93952bf14cfe5a51e9e789a248c45012d7680a10392062fd359d9353be469b2a4402dad3942f7e6a3797a04bc8dc651815e3318e
languageName: node
linkType: hard
"@theatre/studio@workspace:*, @theatre/studio@workspace:theatre/studio":
version: 0.0.0-use.local
resolution: "@theatre/studio@workspace:theatre/studio"
@ -8563,6 +8606,16 @@ __metadata:
languageName: node
linkType: hard
"@types/jest@npm:^29.2.3":
version: 29.2.3
resolution: "@types/jest@npm:29.2.3"
dependencies:
expect: ^29.0.0
pretty-format: ^29.0.0
checksum: 55370906711b600a05b9e497c22aa74d80d8adcdbe4ac2f1bc9311f6f6ca0dd192862b6f38df6ac0d45e92396bcd796e377b1d8058c10bdfd584aeee580c3ce1
languageName: node
linkType: hard
"@types/js-cookie@npm:2.2.6, @types/js-cookie@npm:^2.2.6":
version: 2.2.6
resolution: "@types/js-cookie@npm:2.2.6"
@ -8618,6 +8671,15 @@ __metadata:
languageName: node
linkType: hard
"@types/lodash-es@npm:^4.17.6":
version: 4.17.6
resolution: "@types/lodash-es@npm:4.17.6"
dependencies:
"@types/lodash": "*"
checksum: 9bd239dd525086e278821949ce12fbdd4f100a060fed9323fc7ad5661113e1641f28a7ebab617230ed3474680d8f4de705c1928b48252bb684be6ec9eed715db
languageName: node
linkType: hard
"@types/lodash@npm:*":
version: 4.14.168
resolution: "@types/lodash@npm:4.14.168"
@ -8712,6 +8774,13 @@ __metadata:
languageName: node
linkType: hard
"@types/node@npm:^18.11.9":
version: 18.11.9
resolution: "@types/node@npm:18.11.9"
checksum: cc0aae109e9b7adefc32eecb838d6fad931663bb06484b5e9cbbbf74865c721b03d16fd8d74ad90e31dbe093d956a7c2c306ba5429ba0c00f3f7505103d7a496
languageName: node
linkType: hard
"@types/node@npm:^18.7.20":
version: 18.11.13
resolution: "@types/node@npm:18.11.13"
@ -9030,11 +9099,11 @@ __metadata:
linkType: hard
"@types/yargs@npm:^17.0.8":
version: 17.0.17
resolution: "@types/yargs@npm:17.0.17"
version: 17.0.14
resolution: "@types/yargs@npm:17.0.14"
dependencies:
"@types/yargs-parser": "*"
checksum: 4f1b5149e794c8960652b4339dc96655e53b48fdbe1b847fcb0db95e72e760724a4c5c616a7fccb3c0ae8beb0e57e06e37391d492e916e3ff179aafeb890e426
checksum: 7c571560434e1295b31dfd7f8d3b4a88dbb8bfe8db0054cea35f829f86b1251f67e41eaa0cb5990f17e5ed9b1a508c686b2b9f15c3bafc467ba58989ac9223e8
languageName: node
linkType: hard
@ -11579,6 +11648,26 @@ __metadata:
languageName: node
linkType: hard
"benchmarks@workspace:packages/benchmarks":
version: 0.0.0-use.local
resolution: "benchmarks@workspace:packages/benchmarks"
dependencies:
"@theatre/core": "workspace:*"
"@theatre/core-0.5.0": "npm:@theatre/core@0.5.0"
"@theatre/dataverse-0.5.0": "npm:@theatre/dataverse@0.5.0"
"@theatre/r3f": "workspace:*"
"@theatre/studio": "workspace:*"
"@theatre/studio-0.5.0": "npm:@theatre/studio@0.5.0"
"@types/jest": ^29.2.3
"@types/lodash-es": ^4.17.6
"@types/node": ^18.11.9
"@types/react": ^18.0.25
esbuild: ^0.15.15
esbuild-register: ^3.4.1
typescript: 4.6.x
languageName: unknown
linkType: soft
"bfj@npm:^7.0.2":
version: 7.0.2
resolution: "bfj@npm:7.0.2"
@ -15221,6 +15310,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-android-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-android-64@npm:0.15.15"
conditions: os=android & cpu=x64
languageName: node
linkType: hard
"esbuild-android-arm64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-android-arm64@npm:0.13.15"
@ -15228,6 +15324,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-android-arm64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-android-arm64@npm:0.15.15"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard
"esbuild-darwin-64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-darwin-64@npm:0.13.15"
@ -15235,6 +15338,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-darwin-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-darwin-64@npm:0.15.15"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard
"esbuild-darwin-arm64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-darwin-arm64@npm:0.13.15"
@ -15242,6 +15352,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-darwin-arm64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-darwin-arm64@npm:0.15.15"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard
"esbuild-freebsd-64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-freebsd-64@npm:0.13.15"
@ -15249,6 +15366,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-freebsd-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-freebsd-64@npm:0.15.15"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard
"esbuild-freebsd-arm64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-freebsd-arm64@npm:0.13.15"
@ -15256,6 +15380,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-freebsd-arm64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-freebsd-arm64@npm:0.15.15"
conditions: os=freebsd & cpu=arm64
languageName: node
linkType: hard
"esbuild-jest@npm:^0.5.0":
version: 0.5.0
resolution: "esbuild-jest@npm:0.5.0"
@ -15276,6 +15407,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-linux-32@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-32@npm:0.15.15"
conditions: os=linux & cpu=ia32
languageName: node
linkType: hard
"esbuild-linux-64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-linux-64@npm:0.13.15"
@ -15283,6 +15421,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-linux-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-64@npm:0.15.15"
conditions: os=linux & cpu=x64
languageName: node
linkType: hard
"esbuild-linux-arm64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-linux-arm64@npm:0.13.15"
@ -15290,6 +15435,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-linux-arm64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-arm64@npm:0.15.15"
conditions: os=linux & cpu=arm64
languageName: node
linkType: hard
"esbuild-linux-arm@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-linux-arm@npm:0.13.15"
@ -15297,6 +15449,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-linux-arm@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-arm@npm:0.15.15"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard
"esbuild-linux-mips64le@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-linux-mips64le@npm:0.13.15"
@ -15304,6 +15463,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-linux-mips64le@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-mips64le@npm:0.15.15"
conditions: os=linux & cpu=mips64el
languageName: node
linkType: hard
"esbuild-linux-ppc64le@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-linux-ppc64le@npm:0.13.15"
@ -15311,6 +15477,27 @@ __metadata:
languageName: node
linkType: hard
"esbuild-linux-ppc64le@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-ppc64le@npm:0.15.15"
conditions: os=linux & cpu=ppc64
languageName: node
linkType: hard
"esbuild-linux-riscv64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-riscv64@npm:0.15.15"
conditions: os=linux & cpu=riscv64
languageName: node
linkType: hard
"esbuild-linux-s390x@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-linux-s390x@npm:0.15.15"
conditions: os=linux & cpu=s390x
languageName: node
linkType: hard
"esbuild-loader@npm:^2.13.1":
version: 2.13.1
resolution: "esbuild-loader@npm:2.13.1"
@ -15335,6 +15522,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-netbsd-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-netbsd-64@npm:0.15.15"
conditions: os=netbsd & cpu=x64
languageName: node
linkType: hard
"esbuild-openbsd-64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-openbsd-64@npm:0.13.15"
@ -15342,6 +15536,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-openbsd-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-openbsd-64@npm:0.15.15"
conditions: os=openbsd & cpu=x64
languageName: node
linkType: hard
"esbuild-register@npm:^2.5.0":
version: 2.5.0
resolution: "esbuild-register@npm:2.5.0"
@ -15352,6 +15553,17 @@ __metadata:
languageName: node
linkType: hard
"esbuild-register@npm:^3.4.1":
version: 3.4.1
resolution: "esbuild-register@npm:3.4.1"
dependencies:
debug: ^4.3.4
peerDependencies:
esbuild: ">=0.12 <1"
checksum: 02750477b7215101bd2ffa3eae5064026586afd9a5267e94f5b81722c85c8063794c06328e618b5a93d7b0db4138a092417cfc024471b8a3616d212d09e3d868
languageName: node
linkType: hard
"esbuild-sunos-64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-sunos-64@npm:0.13.15"
@ -15359,6 +15571,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-sunos-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-sunos-64@npm:0.15.15"
conditions: os=sunos & cpu=x64
languageName: node
linkType: hard
"esbuild-windows-32@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-windows-32@npm:0.13.15"
@ -15366,6 +15585,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-windows-32@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-windows-32@npm:0.15.15"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard
"esbuild-windows-64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-windows-64@npm:0.13.15"
@ -15373,6 +15599,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-windows-64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-windows-64@npm:0.15.15"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard
"esbuild-windows-arm64@npm:0.13.15":
version: 0.13.15
resolution: "esbuild-windows-arm64@npm:0.13.15"
@ -15380,6 +15613,13 @@ __metadata:
languageName: node
linkType: hard
"esbuild-windows-arm64@npm:0.15.15":
version: 0.15.15
resolution: "esbuild-windows-arm64@npm:0.15.15"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard
"esbuild@npm:^0.11.19":
version: 0.11.19
resolution: "esbuild@npm:0.11.19"
@ -15469,6 +15709,83 @@ __metadata:
languageName: node
linkType: hard
"esbuild@npm:^0.15.15":
version: 0.15.15
resolution: "esbuild@npm:0.15.15"
dependencies:
"@esbuild/android-arm": 0.15.15
"@esbuild/linux-loong64": 0.15.15
esbuild-android-64: 0.15.15
esbuild-android-arm64: 0.15.15
esbuild-darwin-64: 0.15.15
esbuild-darwin-arm64: 0.15.15
esbuild-freebsd-64: 0.15.15
esbuild-freebsd-arm64: 0.15.15
esbuild-linux-32: 0.15.15
esbuild-linux-64: 0.15.15
esbuild-linux-arm: 0.15.15
esbuild-linux-arm64: 0.15.15
esbuild-linux-mips64le: 0.15.15
esbuild-linux-ppc64le: 0.15.15
esbuild-linux-riscv64: 0.15.15
esbuild-linux-s390x: 0.15.15
esbuild-netbsd-64: 0.15.15
esbuild-openbsd-64: 0.15.15
esbuild-sunos-64: 0.15.15
esbuild-windows-32: 0.15.15
esbuild-windows-64: 0.15.15
esbuild-windows-arm64: 0.15.15
dependenciesMeta:
"@esbuild/android-arm":
optional: true
"@esbuild/linux-loong64":
optional: true
esbuild-android-64:
optional: true
esbuild-android-arm64:
optional: true
esbuild-darwin-64:
optional: true
esbuild-darwin-arm64:
optional: true
esbuild-freebsd-64:
optional: true
esbuild-freebsd-arm64:
optional: true
esbuild-linux-32:
optional: true
esbuild-linux-64:
optional: true
esbuild-linux-arm:
optional: true
esbuild-linux-arm64:
optional: true
esbuild-linux-mips64le:
optional: true
esbuild-linux-ppc64le:
optional: true
esbuild-linux-riscv64:
optional: true
esbuild-linux-s390x:
optional: true
esbuild-netbsd-64:
optional: true
esbuild-openbsd-64:
optional: true
esbuild-sunos-64:
optional: true
esbuild-windows-32:
optional: true
esbuild-windows-64:
optional: true
esbuild-windows-arm64:
optional: true
bin:
esbuild: bin/esbuild
checksum: 9a194a310ac7d6989d1fe7354901d531d3b0d4cc1897a85a7cb9f1ae0fe8d82eb59747e63c91f676bab7bed8d6a1f28f620d49f043e7bd6203f9afe34031f739
languageName: node
linkType: hard
"esbuild@npm:^0.16.7":
version: 0.16.7
resolution: "esbuild@npm:0.16.7"
@ -16604,7 +16921,7 @@ __metadata:
languageName: node
linkType: hard
"expect@npm:^29.3.1":
"expect@npm:^29.0.0, expect@npm:^29.3.1":
version: 29.3.1
resolution: "expect@npm:29.3.1"
dependencies:
@ -26841,7 +27158,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard
"pretty-format@npm:^29.3.1":
"pretty-format@npm:^29.0.0, pretty-format@npm:^29.3.1":
version: 29.3.1
resolution: "pretty-format@npm:29.3.1"
dependencies: