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

NativeAOT support for GarnetServer #74

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

neon-sunset
Copy link

This PR makes progress towards supporting NativeAOT publish of GarnetServer. For now, NativeAOT support for the nuget itself is out of scope as I suspect the users first and foremost care about the application itself.

If the size of PR gets too large, it may be split into multiple as there are a few areas that need to be refactored to be AOT-compatible:

  • Custom "configuration binder" for Options and RedisOptions
  • Options validator
  • ArrayCommands

Ideally, it should overall improve the state of codebase as there are existing tools like System.CommandLine or M.E.C.ConfigurationBinder (or similar) which provide the features required by Garnet in a more robust, trim and AOT compatible way.

…m binary-only GarnetServer and address low-hanging fruit AOT/Trim warnings
@neon-sunset
Copy link
Author

@microsoft-github-policy-service agree

@TalZaccai
Copy link
Contributor

Hey @neon-sunset! Thanks for your willingness to contribute to Garnet!

I'm not sure if what you're suggesting here is possible to support, as we do support custom commands that are dynamically loaded from local dlls on the server (See RespServerSession.RegisterCustomCommands in Garnet.server/Resp/ArrayCommands.cs).

Let me know what you think!

Tal.

@PaulusParssinen
Copy link
Contributor

PaulusParssinen commented Mar 22, 2024

It maybe possible to introduce a compile time feature-switch for the custom command support, which can be enabled by default but toggled by the developers who want the AOT benefits.

I haven't investigated how much work introducing such switch would be in Garnet's case but the feature switches are common approach in .NET to toggle some functionality that can't be trimmed. The .NET runtime itself uses such feature switches, for example, to disable and trim reflection stack in its entirety.

edit: Nevermind, above would be approach for any features in the NuGet libraries that are hard to trim.

For the Garnet.Server, we could introduce the option to disable custom command as command-line switch (again opt-in presumably) and guard the custom command logic with RuntimeFeature.IsDynamicCodeSupported? This should allow building and packaging separate AOT compatible server binary 🤔

@neon-sunset
Copy link
Author

@TalZaccai @PaulusParssinen Indeed, I was mostly going over the list of trim and AOT warnings, and either addressing them or writing down for future work.

Yes, it makes sense to guard the dependent loading with a check and add an informative error else clause when NAOT is targeted. Once NAOT binaries are published and released, there could simply be a notice regarding JIT-dependent feature(s). I don't think it makes sense to add a toggle to explicitly disable this feature for JIT deployment too, or at least, if that is still desired, it can be done separately. I will continue to work on this a little bit later, thank you for the assistance :)

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.

None yet

4 participants