Sw

Switchboard – Dependency Injection for Unity, Log Files, Zero GC

Hacker News

Switchboard – Dependency Injection for Unity, Log Files, Zero GC

I've been a professional game engineer for over 10 years, working with Unity for most of that time. Around when the pandemic started, I was at a point where I could start a new version of an existing project, rebuilding everything from scratch. So, I investigated this "Dependency Injection" concept I had heard about, and how it could be better than using singletons. If you've worked with Unity you know that singletons are prolific in that environment. You mostly create scripts derived from MonoBehaviours that get instantiated for you, so there is no opportunity for constructor injection. Other dependency injection frameworks for Unity mostly mirror the way it's done in other environments, and end up using reflection to get the job done in Unity. To make a long story short, I ended up creating a novel design pattern (correct me if I'm wrong) that I call the Injector Locator Pattern. It accomplishes inversion of control in Unity without any use of reflection. The first service I thought to inject was a logger. Unity, especially when I started, did not have good log files. The performance is poor, and it generates a lot of garbage memory allocations. To make yet another long story short, I ended up creating a replacement for StringBuilder that does not allocate garbage memory when appending numerical values. (StringBuilder still does that in Unity 2021/2022.) Also, I realized that .NET literally cannot render the exact value of certain floating-point numbers. So, I made sure that you can render any float or double to any degree of precision, formatted however you like. Even the values displayed in Visual Studio's debugger are wrong! Anyway, you can essentially use the standard .NET ILogger interface, in Unity, loosely coupled and injected, and write thousands of log entries in a fraction of a second that get written out to UTF-8 log files, with zero GC allocations at any point along the way. Please let me know what you think of my Injector Locator Pattern, my replacement for StringBuilder, and anything else. Thanks!

Share card

Actual performance

3points
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Strong signals: started · Missing: supports, reddit linkedin, podcasting
88%88% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: new, visual, single · Missing: mac, agents, macos
77%77% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
TrustMRRFits verified-revenue profile · Strong signals: way · Missing: mobile apps, ios, personal
56%56% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Strong signals: interface, builder · Missing: plus, platform, intuitive
45%45% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: exist, existing, game engine · Missing: https docs, excited, just released
38%38% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
19%19% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

I
I made a website to view Unity log files45%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

I made a website to view Unity log files

Hacker News1
Lo
Logwise, analyse your log files46%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Logwise, analyse your log files

Hacker News3
Li
Livestream Unity Scenes to WebXR48%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Livestream Unity Scenes to WebXR

Hacker News1
BR
BREP – Binary Search compressed files at O(log n)51%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

BREP – Binary Search compressed files at O(log n)

Hacker News1
My
My First Unity Game42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

My First Unity Game

Hacker News1
My
My girlfriend made her first Unity Game: Flappy Pipes42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

My girlfriend made her first Unity Game: Flappy Pipes

Hacker News1
Sk
SkyRunner, my submission to the 'Kii to Unity' game contest.30%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

SkyRunner, my submission to the 'Kii to Unity' game contest.

Hacker News1
My
My first WP8 game – Made with Unity42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

My first WP8 game – Made with Unity

Hacker News52
I
I made a zero-log, ephemeral, E2EE web chat70%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

I made a zero-log, ephemeral, E2EE web chat

Hacker News2
Be
Beginner Unity 3D Tutorial36%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Beginner Unity 3D Tutorial

Hacker News2