Skip to content

Difference from regular use of C#

Xytabich edited this page Mar 23, 2022 · 15 revisions

General

The execution of programs on Udon and CLR is different, namely:

  • The main difference is that the instruction set in Udon is only intended to work with addresses, not values.
  • Udon uses a stack of addresses, not a stack of values ​​like the CLR. So some things such as recursion are quite expensive to implement in terms of performance.
  • CLR can use some arithmetic or logical operations directly on "raw" data, so all integers (like byte, short and etc.) are converted to 32 or 64 bit numbers. While in Udon it is necessary to use a strongly typed method, and this can lead to constant number conversions.

Katsudon may not support some of the optimization tricks that can be used in IL.

Not supported functionality

  • Custom struct types are not supported because they must always be copied, which is bad for performance. But perhaps they will be introduced but with a warning at compile time.
  • Recursion is not supported, and most likely will not be introduced
  • Static fields are not yet supported

Supported functionality

  • Supports inheritance, interfaces, abstract and generic types for behaviors. But so far this only works between types from katsudon assemblies.
  • Method overloading supported
  • Static methods are supported, they are inlined into the executable code
  • Supported attribute [MethodImpl(MethodImplOptions.AggressiveInlining)] for private method
  • The checked and unchecked context is supported when converting values, but it is recommended to always use checked as it uses fewer udon operations
  • Delegates and events are supported, but without in/out/ref arguments
  • Custom enums are supported
  • Using Nullable<T>(example: int? intOrNull;) are supported
  • Custom classes are supported (but with differences, more details below)

Functional differences

  • Casting of types and as/is completely works only for types from katsudon assemblies. Otherwise, the conversion is skipped.
  • In/out/ref arguments are only supported for methods with inlining
  • Generic methods (i.e. methods that have their own set of generic parameters, and not methods defined in a generic type) are not fully supported, but only for methods with inlining
  • The unchecked context is always used for arithmetic operations
  • Properties and methods with simple assignment or return values ​​when called will be omitted and fields will be used directly
  • Custom data types (classes) do not support inheritance and implementation of interfaces at the moment. Constructors and methods of these classes are inlined when called.
  • Behaviours constructors are executed at compile time, so all values ​​will be "frozen" at compile time. For example: private DateTime startTime = DateTime.Now; will have the date and time at the time of assembly, and not at the time of loading the UdonBehaviour, so such things should be assigned in Start or other methods.
Clone this wiki locally