Skip to content
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

Add a UserType flag for registered types, and use it to improve the performance for is_user_type. #5017

Merged
merged 2 commits into from
Oct 22, 2018

Commits on Oct 19, 2018

  1. Refactor type map to have a separate flag field for each type instead…

    … of magic location in the array.
    
    Refactor the type map to have a separate flag field for each type instead of a
    magic location in the array. This simplifies some code, but also allows us to
    introduce more flags in the future (which becomes increasingly complex if the
    location in the array is to determine yet another value).
    
    This has neglible performance impacts.
    rolfbjarne committed Oct 19, 2018
    Configuration menu
    Copy the full SHA
    7280c9b View commit details
    Browse the repository at this point in the history
  2. Add a UserType flag for registered types, and use it to improve the p…

    …erformance for is_user_type.
    
    Reflection in the Objective-C runtime is apparently quite slow, so try to
    avoid it by computing the information we need for determining whether a
    particular Objective-C type represents a user type or not in the static
    registrar.
    
    We store this information in a flag for the type in question in the type map,
    and use a binary search to search the type map when needed.
    
    This provides a significant improvement, in particular in the dontlink
    scenario (probably because there are many more Objective-C types in the app,
    which made Objective-C reflection slow). In fact, it somehow made the dontlink
    scenario so fast that it's faster than the linkall scenario (which also
    improved, but not nearly as much). While quite inexplicable, it's a consistent
    result I've seen over multiple test runs.
    
    Numbers
    =======
    
    Test case: rolfbjarne/TestApp@004283d
    
    Fix 1 refers to PR xamarin#5009.
    Fix 2 refers to PR xamarin#5013.
    Fix 3 refers to PR xamarin#5016.
    Fix 4 is this fix.
    
    iPad Air 2
    ----------
    
    | Configuration       | Before | After fix 1 | After fix 2  | After fix 3  | After fix 4  | Improvement from fix 3 to fix 4 | Cumulative improvement |
    | ------------------- | ------ | ----------: | -----------: | -----------: | -----------: | ------------------------------: | ---------------------: |
    | Release (link all)  | 477 ms |      481 ms |       224 ms |       172 ms |       148 ms |                     24 ms (14%) |           329 ms (69%) |
    | Release (dont link) | 738 ms |      656 ms |       377 ms |       201 ms |       146 ms |                     55 ms (27%) |           592 ms (80%) |
    
    iPhone X
    --------
    
    | Configuration       | Before | After fix 1 | After fix 2  | After fix 3  | After fix 4  | Improvement from fix 3 to fix 4 | Cumulative improvement |
    | ------------------- | ------ | ----------: | -----------: | -----------: | -----------: | ------------------------------: | ---------------------: |
    | Release (link all)  |  98 ms |       99 ms |        42 ms |        31 ms |        29 ms |                      2 ms ( 6%) |            69 ms (70%) |
    | Release (dont link) | 197 ms |      153 ms |        91 ms |        43 ms |        28 ms |                     15 ms (35%) |           169 ms (86%) |
    
    When linking all assemblies, the type map has 24 entries, and when not linking
    at all it has 2993 entries.
    
    This is part 4 (the last) of multiple fixes for xamarin#4936.
    
    The total speed-up is 69-86% (3-7x faster).
    rolfbjarne committed Oct 19, 2018
    Configuration menu
    Copy the full SHA
    267b0b2 View commit details
    Browse the repository at this point in the history