-
-
Notifications
You must be signed in to change notification settings - Fork 328
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
Use System.Text.Json to replace Newtonsoft.Json for better performance #3174
Conversation
This comment has been minimized.
This comment has been minimized.
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
📝 WalkthroughWalkthroughThe pull request introduces changes to the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Plugins/Flow.Launcher.Plugin.PluginsManager/Utilities.cs (1)
74-77
: Consider async/await for better performanceFor better scalability and performance, consider making the method async:
-internal static UserPlugin GetPluginInfoFromZip(string filePath) +internal static async Task<UserPlugin> GetPluginInfoFromZipAsync(string filePath) { var plugin = null as UserPlugin; - using (ZipArchive archive = System.IO.Compression.ZipFile.OpenRead(filePath)) + using (ZipArchive archive = await Task.Run(() => System.IO.Compression.ZipFile.OpenRead(filePath))) { var pluginJsonPath = archive.Entries.FirstOrDefault(x => x.Name == "plugin.json").ToString(); ZipArchiveEntry pluginJsonEntry = archive.GetEntry(pluginJsonPath); if (pluginJsonEntry != null) { - using StreamReader reader = new StreamReader(pluginJsonEntry.Open()); - string pluginJsonContent = reader.ReadToEnd(); - plugin = JsonSerializer.Deserialize<UserPlugin>(pluginJsonContent); + using var stream = pluginJsonEntry.Open(); + plugin = await JsonSerializer.DeserializeAsync<UserPlugin>(stream, options); plugin.IcoPath = "Images\\zipfolder.png"; } } return plugin; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Plugins/Flow.Launcher.Plugin.PluginsManager/Utilities.cs
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: gitStream.cm
🔇 Additional comments (2)
Plugins/Flow.Launcher.Plugin.PluginsManager/Utilities.cs (2)
6-6
: LGTM!Appropriate addition of the System.Text.Json namespace.
74-77
: 🛠️ Refactor suggestionConfigure JsonSerializer options for compatibility with Newtonsoft.Json
While the migration to System.Text.Json is good for performance, it handles certain scenarios differently from Newtonsoft.Json. To ensure compatibility, consider adding serialization options.
- plugin = JsonSerializer.Deserialize<UserPlugin>(pluginJsonContent); + var options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + AllowTrailingCommas = true + }; + plugin = JsonSerializer.Deserialize<UserPlugin>(pluginJsonContent, options);Let's verify if there are any specific JSON property naming conventions in existing plugin.json files:
} | ||
using StreamReader reader = new StreamReader(pluginJsonEntry.Open()); | ||
string pluginJsonContent = reader.ReadToEnd(); | ||
plugin = JsonSerializer.Deserialize<UserPlugin>(pluginJsonContent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember there's an overload for stream directly so we don't need to read it as string before deserializing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, please check.
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. If the flagged items are 🤯 false positivesIf items relate to a ...
|
Use System.Text.Json to replace Newtonsoft.Json for better performance & Improve code quality