Closed samreid closed 1 year ago
@arouinfar and @kathy-phet and I discussed this today, and were surprised to see that
const x = new NumberProperty( 0, {
range: new Range( -10, 10 ),
tandem: Tandem.GENERAL_MODEL.createTandem( 'myAwesomeNumberProperty' )
} );
x.value = 11;
Ended up with x.value = 11. Same with
phetioClient.invoke( 'gravityAndOrbits.general.model.myAwesomeNumberProperty', 'setValue', [ 11 ] );
We also discussed that a graceful method would take more CPU. We could say that graceful
only defaults to true for phet-io instrumented things. Or maybe always defaults to graceful: true
. But @kathy-phet thinks the main benefit may be around phet-io.
We would like to raise this to a dev team discussion. Before that, @samreid could run performance testing.
@kathy-phet also indicated that @zepumph has been instrumental in building the validation library, and his input would be valuable here.
In dev meeting:
We need some data on performance impact of adding validators. Back to @samreid.
I'd also like to request @zepumph's opinion on this issue (even before we have performance data).
I'm unsure exactly what I'm commenting on. In built versions when assertions are not enabled, we have long had the philosophy to do the best we can, so the example in https://github.com/phetsims/axon/issues/419#issuecomment-1256516874 makes sense if validation isn't occurring.
If we want to have a property where we turn validation off, don't we already have that ability by just using a Property without validation supplied? Or specifying our own validation that specifically ignores the parts we need to be graceful to?
For localeProperty, the main issue seems to be that we want Studio have good UI, but also for validValues to be a no-op (https://github.com/phetsims/joist/blob/9ddbe2ac36d02add2b7e0385f47dc9a74dac085a/js/i18n/localeProperty.ts#L55). The solution there is to fix Studio's UI, not to redefine a way of supplying validation metadata to LocaleProperty for it to specifically be ignored.
Happy to discuss further! I'm sure I'm missing something.
Here's a patch for testing:
Let's try at least 2 sims. Build and unbuilt. With and without assertions. Different browsers. Different platforms. With and without the patch. Maybe measure time to LCP? https://web.dev/lcp/?utm_source=devtools And some way of measuring performance as the sim animates? Throw away first run of each set. Use T-test for independent means: https://www.socscistatistics.com/tests/studentttest/default2.aspx
Memory is not a concern since the validator is stored whether assertions are enabled or not. The patch may actually reduce memory since it decreases the number of closures by N, where N is the number of ReadOnlyProperty instances.
Results of 1st experiment, copy/pasted from excel. Times are in milliseconds, smaller is faster=better.
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
sim | Gravity and Orbits | -- | -- | -- built? | Unbuilt | browser | OSX/Chrome | assertions | Without assertions | condition | WITHOUT PATCH | WITH PATCH timing | LCP | LCP run 1 | 1681.9 | 1725.2 run 2 | 1692.8 | 1719.4 run 3 | 1697.8 | 1724.6 run 4 | 1646.6 | 1764.8 run 5 | 1709.5 | 1724.7
In https://github.com/phetsims/phet-io/issues/1881#issuecomment-1255667686 we discussed that (at least for PhET-iO),
localeProperty
should behave gracefully when trying to set a non-existant locale. If that behavior is also deemed acceptable for PhET brand, then it would make sense to add a Property optiongraceful
which has the following behavior:isValidValue
before setting the value. If the value is valid, proceed with the set (could disable the post-set assertion if we want to save a CPU cycle). If the value is invalid, do not try to set the value at all. This would need to work whether or not assertions are enabled. (So we would have to make sure we are not stripping out validators, which I don't think we are).