-
Notifications
You must be signed in to change notification settings - Fork 283
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
Write configs asynchronously, first part of async API rewrite #1510
Open
goaaats
wants to merge
2
commits into
goatcorp:master
Choose a base branch
from
goaaats:async_write
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−23
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
Dalamud/Interface/Internal/Windows/Data/Widgets/VfsWidget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
using Dalamud.Configuration.Internal; | ||
using Dalamud.Storage; | ||
using ImGuiNET; | ||
using Serilog; | ||
|
||
namespace Dalamud.Interface.Internal.Windows.Data.Widgets; | ||
|
||
/// <summary> | ||
/// Widget for displaying configuration info. | ||
/// </summary> | ||
internal class VfsWidget : IDataWindowWidget | ||
{ | ||
private int numBytes = 1024; | ||
private int reps = 1; | ||
|
||
/// <inheritdoc/> | ||
public string[]? CommandShortcuts { get; init; } = { "vfs" }; | ||
|
||
/// <inheritdoc/> | ||
public string DisplayName { get; init; } = "VFS"; | ||
|
||
/// <inheritdoc/> | ||
public bool Ready { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public void Load() | ||
{ | ||
this.Ready = true; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Draw() | ||
{ | ||
var service = Service<ReliableFileStorage>.Get(); | ||
var dalamud = Service<Dalamud>.Get(); | ||
|
||
ImGui.InputInt("Num bytes", ref this.numBytes); | ||
ImGui.InputInt("Reps", ref this.reps); | ||
|
||
var path = Path.Combine(dalamud.StartInfo.WorkingDirectory!, "test.bin"); | ||
|
||
if (ImGui.Button("Write")) | ||
{ | ||
Log.Information("=== WRITING ==="); | ||
var data = new byte[this.numBytes]; | ||
var stopwatch = new Stopwatch(); | ||
var acc = 0L; | ||
|
||
for (var i = 0; i < this.reps; i++) | ||
{ | ||
stopwatch.Restart(); | ||
service.WriteAllBytesAsync(path, data).GetAwaiter().GetResult(); | ||
stopwatch.Stop(); | ||
acc += stopwatch.ElapsedMilliseconds; | ||
Log.Information("Turn {Turn} took {Ms}ms", i, stopwatch.ElapsedMilliseconds); | ||
} | ||
|
||
Log.Information("Took {Ms}ms in total", acc); | ||
} | ||
|
||
if (ImGui.Button("Read")) | ||
{ | ||
Log.Information("=== READING ==="); | ||
var stopwatch = new Stopwatch(); | ||
var acc = 0L; | ||
|
||
for (var i = 0; i < this.reps; i++) | ||
{ | ||
stopwatch.Restart(); | ||
service.ReadAllBytes(path); | ||
stopwatch.Stop(); | ||
acc += stopwatch.ElapsedMilliseconds; | ||
Log.Information("Turn {Turn} took {Ms}ms", i, stopwatch.ElapsedMilliseconds); | ||
} | ||
|
||
Log.Information("Took {Ms}ms in total", acc); | ||
} | ||
|
||
if (ImGui.Button("Test Config")) | ||
{ | ||
var config = Service<DalamudConfiguration>.Get(); | ||
|
||
Log.Information("=== READING ==="); | ||
var stopwatch = new Stopwatch(); | ||
var acc = 0L; | ||
|
||
for (var i = 0; i < this.reps; i++) | ||
{ | ||
stopwatch.Restart(); | ||
config.ForceSave(); | ||
stopwatch.Stop(); | ||
acc += stopwatch.ElapsedMilliseconds; | ||
Log.Information("Turn {Turn} took {Ms}ms", i, stopwatch.ElapsedMilliseconds); | ||
} | ||
|
||
Log.Information("Took {Ms}ms in total", acc); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
using Dalamud.Configuration; | ||
using Dalamud.Configuration.Internal; | ||
|
@@ -338,12 +338,30 @@ public ICallGateSubscriber<T1, T2, T3, T4, T5, T6, T7, T8, TRet> GetIpcSubscribe | |
/// Save a plugin configuration(inheriting IPluginConfiguration). | ||
/// </summary> | ||
/// <param name="currentConfig">The current configuration.</param> | ||
[Obsolete("Prefer SavePluginConfigAsync() to avoid blocking the main thread.")] | ||
public void SavePluginConfig(IPluginConfiguration? currentConfig) | ||
{ | ||
if (currentConfig == null) | ||
return; | ||
|
||
#pragma warning disable CS0618 // Type or member is obsolete | ||
this.configs.Save(currentConfig, this.plugin.InternalName, this.plugin.Manifest.WorkingPluginId); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
|
||
/// <summary> | ||
/// Save a plugin configuration(inheriting IPluginConfiguration). | ||
/// </summary> | ||
/// <param name="currentConfig">The current configuration.</param> | ||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> | ||
public async Task SavePluginConfigAsync(IPluginConfiguration? currentConfig) | ||
{ | ||
if (currentConfig == null) | ||
return; | ||
|
||
#pragma warning disable CS0618 // Type or member is obsolete | ||
await this.configs.SaveAsync(currentConfig, this.plugin.InternalName, this.plugin.Manifest.WorkingPluginId); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
Comment on lines
+362
to
+364
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These pragmas are unnecessary, |
||
|
||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We'll be invoking
DalamudConfigurationSaved
before the save actually completes. This seems fine, given that the only use I can see is updatingDalamudPluginInterface#GeneralChatType
, but it does feel like a behavioral change that should at least be noted.