Event : Visual Studio Users Community Japan #1
Date : 2019/09/14
ソフトウェア/サービス開発において最も後回しにされるものの代表が「パフォーマンスの向上」です。C#/.NET の最大の武器は開発生産性ですが、C# 7.0 以降はパフォーマンス向上のための機能追加が多数行われています。いくつかのポイントを押さえることで実装時からより高速なコードを書くことができるようになります。
このドキュメントでは、そんなポイントとなる箇所をふんだんにお届けします。
A Brief History of UniRx/UniTask, IUniTaskSource in DepthYoshifumi Kawai
The document discusses the architecture of UniTask in C#, including the IUniTaskSource interface and AsyncUniTask class. IUniTaskSource defines methods for getting task results and status and handling completions. AsyncUniTask implements IUniTaskSource and manages a state machine and task pool for asynchronous operations. It retrieves tasks from the pool if available or creates new ones, and returns tasks to the pool after completion.
Deep Dive async/await in Unity with UniTask(EN)Yoshifumi Kawai
The document discusses asynchronous programming in C# using async/await and Rx. It explains that async/await is not truly asynchronous or multithreaded - it is for asynchronous code that runs on a single thread. UniTask is introduced as an alternative to Task that is optimized for Unity's single-threaded environment by avoiding overhead like ExecutionContext and SynchronizationContext. Async/await with UniTask provides better performance than coroutines or Rx observables for Unity.
Memory Management of C# with Unity Native CollectionsYoshifumi Kawai
This document discusses C# and memory management in Unity. It begins by introducing the author and some of their open-source projects related to C# and Unity, including libraries for serialization and reactive programming. It then discusses using async/await with Unity through the UniTask library. The document also covers differences in memory management between .NET Core and Unity due to using different runtimes (CoreCLR vs Unity runtime) and virtual machines. It presents examples of using unsafe code and pointers to directly manage memory in C# for cases like native collections. It concludes that while C# aims for a safe managed world, optimizations require bypassing the runtime through unsafe code, and being aware of memory can help better understand behavior and use APIs more
The document discusses various methods for efficiently serializing and deserializing data in C# using MessagePack, including:
- Methods for reading primitive data types like integers and floats from bytes
- Representing float values as individual bytes for efficient serialization
- Using lookup tables and decoder interfaces to quickly determine MessagePack types and decode values
- Discussing faster alternatives like using direct memory copying instead of serialization delegates
- Mentioning how to extend MessagePack specifications while maintaining compatibility for faster serialization
This document discusses RuntimeUnitTestToolkit, a tool for running unit tests on IL2CPP games. It allows creating unit test classes with public methods that will be automatically registered as tests. Tests can make assertions using the Is method and can be asynchronous by returning IEnumerator. It works with UniRx and allows testing asynchronous coroutines. The tool focuses on play time testing and supports running tests on actual devices.
How to make the Fastest C# Serializer, In the case of ZeroFormatterYoshifumi Kawai
The document discusses ZeroFormatter, an infinitely fast serializer that avoids common serialization inefficiencies. It provides benchmarks showing ZeroFormatter is faster than standard serializers. ZeroFormatter minimizes abstraction by directly writing to byte arrays without boxing or memory streams. Formatter classes handle different types by directly serializing/deserializing values without intermediate serialization steps. This achieves serialization with minimal overhead and memory allocation.
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Yoshifumi Kawai
This document discusses PhotonWire, a framework for building networked games and applications. It allows clients and servers to communicate asynchronously using operations and operation requests/responses. Clients can send messages to servers using operations, which are received and handled via a switch statement based on operation code. Servers can then send response messages back to clients. The document also mentions plans to improve serialization performance in PhotonWire by replacing the current serializer.
IoT Devices Compliant with JC-STAR Using Linux as a Container OSTomohiro Saneyoshi
Security requirements for IoT devices are becoming more defined, as seen with the EU Cyber Resilience Act and Japan’s JC-STAR.
It's common for IoT devices to run Linux as their operating system. However, adopting general-purpose Linux distributions like Ubuntu or Debian, or Yocto-based Linux, presents certain difficulties. This article outlines those difficulties.
It also, it highlights the security benefits of using a Linux-based container OS and explains how to adopt it with JC-STAR, using the "Armadillo Base OS" as an example.
Feb.25.2025@JAWS-UG IoT
5. Reactive Extensions for Unity
https://github.com/neuecc/UniRx/
async/await(UniTask)
async UniTask<string> DemoAsync()
{
// You can await Unity's AsyncObject
var asset = await Resources.LoadAsync<TextAsset>("foo");
// .ConfigureAwait accepts progress callback
await SceneManager.LoadSceneAsync("scene2").ConfigureAwai
// await frame-based operation(you can also await frame c
await UniTask.Delay(TimeSpan.FromSeconds(3));
// like 'yield return WaitForEndOfFrame', or Rx's Observe
await UniTask.Yield(PlayerLoopTiming.PostLateUpdate);
// You can await standard task
await Task.Run(() => 100);
// get async webrequest
async UniTask<string> GetTextAsync(UnityWebRequest req)
{
var op = await req.SendWebRequest();
return op.downloadHandler.text;
}
var task1 = GetTextAsync(UnityWebRequest.Get("http://goog
var task2 = GetTextAsync(UnityWebRequest.Get("http://bing
var task3 = GetTextAsync(UnityWebRequest.Get("http://yaho
// concurrent async-wait and get result easily by tuple s
var (google, bing, yahoo) = await UniTask.WhenAll(task1,
// You can handle timeout easily
await GetTextAsync(UnityWebRequest.Get("http://unity.com"
39. // こんなクラスがあるとして
public class Sample
{
public int Id { get; set; }
public string Name { get; set; }
public string[] Addresses { get; set; }
}
// Object作って
Sample obj = new Sample
{
Id = 10,
Name = "Foo",
Addresses = new[] { "Foo", "Bar", "Baz" }
};
// こんな感じにbyte[]に変換するというAPI
byte[] bin = MessagePackSerializer.Serialize<Sample>(obj);
40. // これを詳細にバラすと
byte[] bin = MessagePackSerializer.Serialize<Sample>(obj);
// Sampleの子シリアライザを取得し
var sampleFormatter = StandardResolver.Instance.GetFormatter<Sample>();
// resultの参照
byte[] bin = null;
// こんな風になっている(refによってbinに結果が詰まってくる)
sampleFormatter.Serialize(ref bin, 0, obj, StandardResolver.Instance);