Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET rewrite #30

Merged
merged 61 commits into from
Apr 3, 2024
Merged

.NET rewrite #30

merged 61 commits into from
Apr 3, 2024

Conversation

dealloc
Copy link
Member

@dealloc dealloc commented Mar 26, 2024

as discussed in #28 the API will be rewritten from Elixir to C#
The main goal is to provide a language/ecosystem that is more accessible to contribution, part of this effort is also the helldivers-2/json repository.

This PR switches over the Elixir implementation to an AOT ASP.NET Core application written in C#

Goals

  • lower memory footprint by keeping as much shared memory
  • fast startup (see below)
  • faster (AOT, no reflection and compiler optimization)
  • higher API limits
  • extensible
  • backwards compatible with ArrowHead's official API
  • approachable for new contributors

Faster, better, stronger

So why is faster startup and lower memory usage through AOT such a big deal?
It basically comes down to the fact that the API is currently hosted on my own costs, and to keep those down as much as possible I try to minimize the KPI's most provides bill for: CPU time and memory usage.

By using less RAM and less CPU I can host the API on a lower tier, saving me costs and allowing me to put in higher API rate limits

Architecture

The new API is divided up in 4 components to give each part (domain) of the application it's own 'space':

  • Helldivers-2-API: contains the actual HTTP API interface, OpenAPI documents and also serves as the runtime host (aka the application that starts)
  • Helldivers-2-Models: contains POCO (P lain O ld C # O bjects) of both the ArrowHead API and the 'new' API surface
  • Helldivers-2-Core: contains the 'snapshot' of information currently being served and mapping from ArrowHead models to domain models
  • Helldivers-2-SourceGen: I admit I may have gone a little overboard, see below)

Source generators

As mentioned, the 4th component is Helldivers-2-SourceGen, which basically does 1 thing:
it generates a class Helldivers.Models.Static with properties for every JSON file pulled in from helldivers-2/json.

Generate source files look a lot like this:

// <auto-generated />
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using global::System.Collections.Generic;

namespace Helldivers.Models;

public static partial class Static
{
    /// <summary>Public list of Factions entries from factions.json</summary>
    public static IReadOnlyDictionary<int, string> Factions = new Dictionary<int, string>()
	{
		{ 1, "Humans" },
		{ 2, "Terminids" },
		{ 3, "Automaton" },
	};
}

This allows us to intern names of sectors, planets etc for even more efficient memory usage.
It also makes sure I don't have to manually write out the names of planets and sectors in the C# code, or load them in at runtime (see 'Faster, better, stronger')

Migration path

if you are using the current API endpoints from the Elixir version, there will be breaking changes.
Please check the OpenAPI documents under Helldivers-2-API/wwwroot/ for details on the new endpoints.
Also feel free to add comments below here for endpoints you are using, and to see how those can be migrated in the new model.

Roadmap

  • map ArrowHead API endpoints
  • implement rate limits
  • add API endpoints for fetching specific domain data
  • map attacks, events and campaigns
  • add documentation
  • document language selection scrapped for later date
  • add contribution guide
  • update CI for .NET
  • update CD for .NET
  • generate documentation for .NET rather than Elixir scrapped for later date
  • publish generated documentation as Github pages site

@dealloc dealloc requested a review from a team March 26, 2024 22:45
@dealloc dealloc self-assigned this Mar 26, 2024
@dealloc dealloc mentioned this pull request Mar 26, 2024
3 tasks
@lambstream
Copy link
Contributor

🎊

lambstream
lambstream previously approved these changes Mar 27, 2024
Copy link
Contributor

@lambstream lambstream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

We should add a task or an issue for the handling of the language detection. (As mentioned in the comments of the ArrowHeadController.

dealloc added a commit that referenced this pull request Mar 27, 2024
@dealloc dealloc added this to the V1 milestone Mar 28, 2024
@dealloc dealloc force-pushed the rewrite/dotnet branch 2 times, most recently from 04173e2 to e0c7afd Compare March 29, 2024 20:19
@dealloc
Copy link
Member Author

dealloc commented Apr 2, 2024

@chatterchats can I ask for your eyes on this PR as well?
Specifically the documentation part around contribution etc, though you're free of course to review other things you'd like as well

@dealloc dealloc marked this pull request as ready for review April 2, 2024 22:43
@chatterchats
Copy link
Contributor

Contribution guide looks good, will be a lot better with the todos are finished there but it's great to get started!

Copy link
Contributor

@lambstream lambstream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@lambstream lambstream merged commit d54c8da into master Apr 3, 2024
1 check passed
@lambstream lambstream deleted the rewrite/dotnet branch April 3, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants