mono / monodevelop

MonoDevelop is a cross platform .NET IDE
http://www.monodevelop.com
2.84k stars 1.02k forks source link

[Mac] Set Marshal*Exception modes #9404

Closed Therzok closed 4 years ago

Therzok commented 4 years ago

This should prevent hard crashing when working with exception handling in xammac

Fixes https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1042626

Therzok commented 4 years ago

@monojenkins rebase

Therzok commented 4 years ago

Testing perf impact myself, to see if it's actually negligible

Therzok commented 4 years ago

For a test scenario of scrolling mcs' expression.cs from top to bottom with a mouse, but can't guarantee it is running the same number of updates, so I scaled to total CPU runtime.

OLD scrollWheel: 441 + 174 / 1589 total - 0.387 total time NEW scrollWheel: 559 + 120 + 20 / 1815 total - 0.385 total time

So the perf impact is negligible - improvement probably due to weighting on scrolling. Below, you see the FPS report. To read it, the idea is that during a sample range, it calculates how many updates it can do to the screen, and both variants are low bounded to 30FPS and reach 60FPS a few times:


----FPS Report Legend:-----
Raw Instantaneous FPS:
    30FPS delimiter:    '|'
    10FPS delimiter:    '+'
    1FPS delimiter:     '-'

Defer+Work Instantaneous FPS:                'X'
Work Instantaneous FPS:                      '^'
Equal Work and Defer+Work Instantaneous FPS: '*'

====Frame Rate Report OLD:====

   Frame Length [SampleRange] WS Wait Length [SampleRange]   Defer Length [SampleRange] WS Work Length [SampleRange]      Frame Rate
        14.27 ms[   40-53   ]         0.00 ms[ No samples]         7.96 ms[   40-47   ]         6.31 ms[   48-53   ]       70.08 FPS|---------+---------+---------|---------+---------+---------*
        36.88 ms[   54-90   ]        16.69 ms[   54-70   ]        10.32 ms[   71-80   ]         9.87 ms[   81-90   ]       27.12 FPS|---------+---------+-------                      X         ^
        29.01 ms[   91-119  ]         0.28 ms[ No samples]        23.01 ms[   91-113  ]         5.73 ms[  114-119  ]       34.47 FPS|---------+---------+---------|----X                        ^
        34.90 ms[  120-154  ]        18.23 ms[  120-137  ]         9.40 ms[  138-146  ]         7.27 ms[  147-154  ]       28.65 FPS|---------+---------+---------                              *
        34.19 ms[  155-188  ]         6.71 ms[  155-160  ]        19.60 ms[  161-180  ]         7.89 ms[  181-188  ]       29.25 FPS|---------+---------+---------      X                       ^
        14.18 ms[  189-202  ]         3.79 ms[  189-192  ]         4.90 ms[  193-197  ]         5.49 ms[  198-202  ]       70.50 FPS|---------+---------+---------|---------+---------+---------*
        36.73 ms[  203-239  ]        14.92 ms[  203-217  ]        12.96 ms[  218-230  ]         8.86 ms[  231-239  ]       27.22 FPS|---------+---------+-------                  X             ^
        14.59 ms[  240-253  ]         0.27 ms[ No samples]         7.69 ms[  240-247  ]         6.63 ms[  248-253  ]       68.54 FPS|---------+---------+---------|---------+---------+---------*
        34.60 ms[  254-288  ]        11.26 ms[  254-265  ]        15.38 ms[  266-280  ]         7.95 ms[  281-288  ]       28.91 FPS|---------+---------+---------             X                ^
        37.28 ms[  289-325  ]        11.66 ms[  289-300  ]        13.68 ms[  301-313  ]        11.94 ms[  314-325  ]       26.83 FPS|---------+---------+-------           X                    ^
        24.83 ms[  326-349  ]         0.46 ms[ No samples]        20.96 ms[  326-346  ]         3.41 ms[  347-349  ]       40.28 FPS|---------+---------+---------|---------+X                  ^
        36.11 ms[  350-386  ]        21.41 ms[  350-371  ]         8.53 ms[  372-379  ]         6.17 ms[  380-386  ]       27.69 FPS|---------+---------+--------                               *
        32.83 ms[  387-418  ]         4.87 ms[  387-390  ]        22.31 ms[  391-413  ]         5.65 ms[  414-418  ]       30.46 FPS|---------+---------+---------|     X                       ^

====Frame Rate Report NEW:====

   Frame Length [SampleRange] WS Wait Length [SampleRange]   Defer Length [SampleRange] WS Work Length [SampleRange]      Frame Rate
        29.12 ms[   33-61   ]         0.00 ms[ No samples]        27.60 ms[   33-60   ]         1.52 ms[     61    ]       34.34 FPS|---------+---------+---------|---X                         ^
        15.86 ms[   62-77   ]        11.63 ms[   62-73   ]         3.27 ms[   74-76   ]         0.96 ms[     77    ]       63.06 FPS|---------+---------+---------|---------+---------+---------*
        17.10 ms[   78-94   ]         4.64 ms[   78-82   ]        11.23 ms[   83-93   ]         1.23 ms[     94    ]       58.48 FPS|---------+---------+---------|---------+---------+-------- *
        50.95 ms[   95-145  ]        17.46 ms[   95-112  ]        31.50 ms[  113-143  ]         1.99 ms[  144-145  ]       19.63 FPS|---------+---------+         X                             ^
        17.95 ms[  146-163  ]         4.55 ms[  146-150  ]        10.19 ms[  151-160  ]         3.21 ms[  161-163  ]       55.70 FPS|---------+---------+---------|---------+---------+------   *
        37.24 ms[  164-199  ]        16.24 ms[  164-179  ]        16.67 ms[  180-195  ]         4.33 ms[  196-199  ]       26.85 FPS|---------+---------+-------                    X           ^
        32.76 ms[  200-232  ]        17.53 ms[  200-217  ]         8.81 ms[  218-226  ]         6.42 ms[  227-232  ]       30.52 FPS|---------+---------+---------|-                            *
        10.57 ms[  233-243  ]         0.21 ms[ No samples]         9.56 ms[  233-242  ]         0.80 ms[    243    ]       94.62 FPS|---------+---------+---------|---------+---------+---------*
        40.97 ms[  244-284  ]        25.39 ms[  244-268  ]         7.66 ms[  269-276  ]         7.91 ms[  277-284  ]       24.41 FPS|---------+---------+----                                   *
        32.57 ms[  285-316  ]        17.47 ms[  285-301  ]         7.97 ms[  302-309  ]         7.13 ms[  310-316  ]       30.70 FPS|---------+---------+---------|-                            *
        34.66 ms[  317-351  ]        13.66 ms[  317-330  ]        12.48 ms[  331-342  ]         8.52 ms[  343-351  ]       28.85 FPS|---------+---------+---------                  X           ^
        15.22 ms[  352-366  ]         0.23 ms[ No samples]         7.94 ms[  352-359  ]         7.05 ms[  360-366  ]       65.70 FPS|---------+---------+---------|---------+---------+---------*
        49.19 ms[  367-415  ]        26.52 ms[  367-393  ]        16.44 ms[  394-409  ]         6.23 ms[  410-415  ]       20.33 FPS|---------+---------+                       X               ^
        37.26 ms[  416-452  ]        13.49 ms[  416-429  ]        13.47 ms[  430-442  ]        10.30 ms[  443-452  ]       26.84 FPS|---------+---------+-------              X                 ^
        47.39 ms[  453-500  ]        28.75 ms[  453-481  ]        11.20 ms[  482-492  ]         7.44 ms[  493-500  ]       21.10 FPS|---------+---------+-                                X     ^
        33.39 ms[  501-533  ]         4.76 ms[  501-504  ]        20.99 ms[  505-525  ]         7.64 ms[  526-533  ]       29.95 FPS|---------+---------+---------|    X                        ^
        31.41 ms[  534-564  ]         7.74 ms[  534-541  ]        17.54 ms[  542-558  ]         6.13 ms[  559-564  ]       31.84 FPS|---------+---------+---------|--         X                 ^
        16.39 ms[  565-581  ]         0.47 ms[    565    ]        10.48 ms[  566-575  ]         5.44 ms[  576-581  ]       61.00 FPS|---------+---------+---------|---------+---------+---------*
        38.04 ms[  582-619  ]         5.39 ms[  582-586  ]        22.70 ms[  587-609  ]         9.95 ms[  610-619  ]       26.29 FPS|---------+---------+------    X                            ^
Therzok commented 4 years ago

This is good to go.

Therzok commented 4 years ago

Attached are the 2 spindump files, the version with this patch is the one at the 01:21 mark Visual Studio_Profile_2019-12-04__01-21-33.txt Visual Studio_Profile_2019-12-04__01-15-25.txt

Therzok commented 4 years ago

objc_msgSend calls do seem higher, but usually increased by 1-2ms for 40ms baseline. Equivalent of a 2% slowdown. So :+1: for the change