-
Notifications
You must be signed in to change notification settings - Fork 328
NEW: Added InputDeviceMatcher.WithManufacturerContains(string noRegexMatch) to improve DualShockSupport initialization performance #1990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…(string) - improve DualShockSupport initialization performance o WithManufacturerContains() provides for simple keyword (no regex) matching in the manufacturer string o Changes DualShock4Gamepad / DualShock3Gamepad matchers to avoid regex creation on initialization These changes save 25ms in DualShockSupport.Initialize during player start-up (26ms -> 1ms)
… noRegexMatch), added chanelog entry (ISX-1411)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I approve the change and the savings.
I've asked a couple of questions though as it looks like a slightly smaller change could give the same result.
Might also be worth adding Lewis Hammond to this PR from the PlayStation team
/// <seealso cref="InputDeviceDescription.manufacturer"/> | ||
public InputDeviceMatcher WithManufacturerContains(string noRegExPattern) | ||
{ | ||
return With(kManufacturerContainsKey, noRegExPattern, supportRegex:false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that supportRegex:false is passed, do you reallly need kManufacturerContainsKey.
It seems you could just use kManufacturerKey since the object type will remain a string
(but I may have missed something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The different key is needed to take the different path through MatchPercentage().
kManufacturerKey -> MatchSingleProperty -> string.Compare(...) == 0 // string/regex needs exactly match
kManufacturerContainsKey -> MatchSinglePropertyContains -> string.Contains(...) // string just needs to be in there somewhere
.WithInterface("HID") | ||
.WithManufacturer("Sony.+Entertainment") | ||
.WithProduct("PLAYSTATION(R)3 Controller")); | ||
.WithManufacturerContains("Sony") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering it this could be just WithManufacturer("Sony", supportRegex:false) ?
There is a small chance this matches wider now - E.g. Entertainment Sony would match now, but I don't think this is likely to be any false positives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it needs to be an exact match as the code does:
string.Compare(...) == 0
... so we would need to provide the entire manufacturer string - and there seem to be two flavours of Sony manufacturer string:
- "Sony Interactive Entertainment"
- "Sony Computer Entertainment"
... hence the regex in the original code.
Just checked this.
.WithManufacturer("Sony", supportRegex:false) // test
... and some of the tests fail.
This is the reason why I added the 'Contains' thing - an explicit non-regex pattern that just has to be in the manufacturer string.
o Was looking for manufacturer string in pattern not pattern in manufacturer string (doh!)
Description
The InputDeviceMatcher.WithManufacturer() can perform a regex match even for simple patterns (eg "Sony.+Entertainment" and "PLAYSTATION(R)3 Controller" are both treated as Regexes) which is surprisingly costly on initialization.
This PR addresses that by adding an API to perform a simple string keyword match on the device manufacturer string,
Changes made
The new WithManufacturerContains(string noRegexMatch) API performs a String.Contains() check instead looking for the simple pattern in the manufacturer string.
Changed the DualShockSupport for DualShock4Gamepad and DualShock3Gamepad to avoid regex matching.
These changes save 25ms in DualShockSupport.Initialize during player start-up (26ms -> 1ms)
Testing
Local testing using SONY controllers and Quest VR devices.
Risk
Previously a controller that reported the manufacturer as "SONY Entertainment" would match - with this change a hypothetical device that reported the manufacturer as "Entertainment Not SONY" would also match. I think this is a risk worth taking.
Checklist
Before review:
Changed
,Fixed
,Added
sections.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.After merge: