Skip to content

Conversation

AlexTyrer
Copy link
Contributor

@AlexTyrer AlexTyrer commented Aug 19, 2024

Description

Comparing escaped and non-escaped strings is very slow - this happens when devices are deactivated/reactivated such as when the Quest2 headset and controllers enter and awake from sleep mode.

The high cost comes from having to compare each string character-by-character (skipping '' escapes) each time entering the C# runtime to perform System.Globalization.ToUpperInvariant.

Changes made

This change to TryMatchDisconnectedDevice() means that any parsed strings that contain escape characters are converted to non-escaped strings for much quicker comparison.

This saves approximately 0.5ms / frame when an Oculus headset or controller is reactivated.

Testing

Local testing with the Quest2 headset and controllers using Superluminal to capture the cost of device awakening.

Risk

We allocate a temporary string where before we did not.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@AlexTyrer AlexTyrer changed the title [InputSystem] JsonParser / ParseStringValue now creates unescaped strings FIX: JsonParser / ParseStringValue now creates unescaped strings Aug 19, 2024
…n TryMatchDisconnectedDevice

o Native deviceDescriptor / capabilities field is escaped Json string
o Managed description.capabilities string is non-escaped Json string
o Use temporary escaped Json string for quicker comparison
o Move MakeEscapedJsonString functionality to its own function
o Devices_RemovingAndReaddingDevice_DoesNotAllocateMemory now expects a single (string) GC allocation per call to ReportNewInputDevice
o Fix for PrimitiveValue ToBoolean for double type (logic was inverted)
@AlexTyrer AlexTyrer requested a review from ekcoh August 22, 2024 14:24
Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks like a good improvement @AlexTyrer

return !Mathf.Approximately(m_FloatValue, default);
case TypeCode.Double:
return NumberHelpers.Approximately(m_DoubleValue, default);
return !NumberHelpers.Approximately(m_DoubleValue, default);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus bug fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I spotted a bug we didn't even know we had!


### Changed
- Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data.
- Improved performance of disconnected device activation (ISX-1450)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could live under ### Fixed since it's not really a changed behavior, right?

@AlexTyrer AlexTyrer merged commit d7b1b86 into develop Sep 2, 2024
@AlexTyrer AlexTyrer deleted the isx-1450-json-parser-unescape-strings branch September 2, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants