Skip to content

Improve performance of HID descriptor parsing and device matching#1579

Merged
andrew-oc merged 1 commit intodevelopfrom
faster_hid_descriptor_parsing
Sep 5, 2022
Merged

Improve performance of HID descriptor parsing and device matching#1579
andrew-oc merged 1 commit intodevelopfrom
faster_hid_descriptor_parsing

Conversation

@andrew-oc
Copy link
Copy Markdown
Contributor

Description

During domain reloads, and during InputTestFixture test teardown, all device descriptions are parsed to see if the system can add any devices that it knows about but couldn't add previously. For HID devices, that means parsing the HID descriptor, which on later version of Unity, contains quite a lot of data. On machines with many HID devices attached, this parsing can get quite expensive.

Changes made

This PR replaces the parsing in the HID descriptor FromJson method with a custom predictive parser that depends on the descriptor being well formatted. If it fails, then processing falls back on the previous method. On 2022.1, this change resulted in full test runs going from 144 seconds down to 110. On previous Unity versions the test run improvement is only about two seconds as the HID descriptors have less data in them in those versions. Domain reload time is still improved though.

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.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • 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.

@andrew-oc andrew-oc requested a review from ekcoh August 31, 2022 13:21
@andrew-oc andrew-oc force-pushed the faster_hid_descriptor_parsing branch from e058d81 to fc41fb3 Compare September 1, 2022 06:44
@andrew-oc andrew-oc requested a review from jimon September 1, 2022 08:07
Copy link
Copy Markdown
Contributor

@jimon jimon left a comment

Choose a reason for hiding this comment

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

Tbh, not happy with this solution, we should just have a fast json parser period, or not use json for this to begin with.

But a good solution today is better than a great solution tomorrow.

@andrew-oc andrew-oc merged commit 6808810 into develop Sep 5, 2022
@andrew-oc andrew-oc deleted the faster_hid_descriptor_parsing branch September 5, 2022 10:08
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