@@ -603,8 +603,8 @@ public void Performance_OptimizedControls_ReadingMousePosition100kTimes(Optimiza
603603 [ TestCase ( OptimizationTestType . OptimizedControlsAndReadValueCaching ) ]
604604 // Currently these tests shows that all the optimizations have a performance cost when reading from a Mouse device.
605605 // OptimizedControls option is slower because of an extra check that is only done in Editor and Development Builds.
606- // ReadValueCaching option is slower because Mouse state is changed every update, which means cached values are
607- // always stale. And there is a cost when caching the value.
606+ // ReadValueCaching option is slower because Mouse state (FastMouse) is changed every update, which means cached
607+ // values are always stale. And currently there is a cost when caching the value.
608608 public void Performance_OptimizedControls_ReadingMousePosition1kTimes ( OptimizationTestType testType )
609609 {
610610 SetInternalFeatureFlagsFromTestType ( testType ) ;
@@ -681,6 +681,43 @@ public void Performance_OptimizedControls_ReadAndUpdateGamepad1kTimes(Optimizati
681681 . Run ( ) ;
682682 }
683683
684+ [ Test , Performance ]
685+ [ Category ( "Performance" ) ]
686+ [ TestCase ( OptimizationTestType . NoOptimization ) ]
687+ [ TestCase ( OptimizationTestType . ReadValueCaching ) ]
688+ // This shows a use case where ReadValueCaching optimization will perform worse when controls have stale cached
689+ // values every frame. Meaning, when control values change in every frame.
690+ public void Performance_OptimizedControls_ReadAndUpdateGamepadNewValuesEveryFrame1kTimes ( OptimizationTestType testType )
691+ {
692+ SetInternalFeatureFlagsFromTestType ( testType ) ;
693+
694+ var gamepad = InputSystem . AddDevice < Gamepad > ( ) ;
695+
696+ InputSystem . Update ( ) ;
697+
698+ Measure . Method ( ( ) =>
699+ {
700+ var pos = new Vector2 ( ) ;
701+ InputSystem . QueueStateEvent ( gamepad , new GamepadState { leftStick = new Vector2 ( 0.1f , 0.1f ) } ) ;
702+ InputSystem . Update ( ) ;
703+
704+ gamepad . leftStick . ReadValue ( ) ;
705+ Assert . That ( gamepad . leftStick . m_CachedValueIsStale , Is . False ) ;
706+
707+ for ( var i = 0 ; i < 1000 ; ++ i )
708+ {
709+ InputSystem . Update ( ) ;
710+ pos = gamepad . leftStick . value ;
711+ Assert . That ( gamepad . leftStick . m_CachedValueIsStale , Is . False ) ;
712+ // Make sure there's a new different value every frames to mark the cached value as stale.
713+ InputSystem . QueueStateEvent ( gamepad , new GamepadState { leftStick = new Vector2 ( i / 1000f , i / 1000f ) } ) ;
714+ }
715+ } )
716+ . MeasurementCount ( 100 )
717+ . WarmupCount ( 10 )
718+ . Run ( ) ;
719+ }
720+
684721 [ Test , Performance ]
685722 [ Category ( "Performance" ) ]
686723 [ TestCase ( OptimizationTestType . NoOptimization ) ]
@@ -693,14 +730,14 @@ public void Performance_OptimizedControls_UpdateOnly1kTimes(OptimizationTestType
693730 {
694731 SetInternalFeatureFlagsFromTestType ( testType ) ;
695732
696- // This adds a FastMouse, which updates state every frame and can lead to a performance cost when using ReadValueCaching.
733+ // This adds FastMouse, which updates state every frame and can lead to a performance cost
734+ // when using ReadValueCaching.
697735 var mouse = InputSystem . AddDevice < Mouse > ( ) ;
698736 InputSystem . Update ( ) ;
699737
700738 Measure . Method ( ( ) =>
701739 {
702- for ( var i = 0 ; i < 1000 ; ++ i )
703- InputSystem . Update ( ) ;
740+ CallUpdate ( ) ;
704741 } )
705742 . MeasurementCount ( 100 )
706743 . SampleGroup ( "Mouse Only" )
@@ -713,13 +750,19 @@ public void Performance_OptimizedControls_UpdateOnly1kTimes(OptimizationTestType
713750
714751 Measure . Method ( ( ) =>
715752 {
716- for ( var i = 0 ; i < 1000 ; ++ i )
717- InputSystem . Update ( ) ;
753+ CallUpdate ( ) ;
718754 } )
719755 . MeasurementCount ( 100 )
720756 . SampleGroup ( "Gamepad Only" )
721757 . WarmupCount ( 10 )
722758 . Run ( ) ;
759+
760+ return ;
761+
762+ void CallUpdate ( )
763+ {
764+ for ( var i = 0 ; i < 1000 ; ++ i ) InputSystem . Update ( ) ;
765+ }
723766 }
724767
725768#if ENABLE_VR
0 commit comments