Search Unity

TextMesh Pro FastAction questions

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by Peter77, Aug 22, 2019.

  1. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    4,029
    TMP comes with various FastAction classes. The name suggests it's faster than using System.Action, but looking at the code, it uses System.Action internally.

    It seems FastAction is a layer on top of System.Action, but why?
    Do you have numbers how much faster it is?
    Is it safe to assume to use FastAction over Action always?
    Are there cases where using Action is more benefitial than using FastAction?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    3,192
    Those were implemented a long time ago as an alternative to using delegates which are immutable where using += operator generates allocations as the delegate list is recreated.

    Essentially it consists of replacing the raw delegates with wrapper classes that can handle registering to delegates and removal of them in constant time instead of linear time.

    This implementation was the contribution by a TMP user back then :)
     
    Peter77 likes this.
  3. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    4,029
    I see, thanks for the quick response!