Skip to content

アセンブル速度高速化#443

Open
ueno1969 wants to merge 2 commits intoAILight:mainfrom
ueno1969:speed_up-5
Open

アセンブル速度高速化#443
ueno1969 wants to merge 2 commits intoAILight:mainfrom
ueno1969:speed_up-5

Conversation

@ueno1969
Copy link
Contributor

アセンブル速度高速化しました。ベンチマーク上は10%程度早くなっています。

  • CompareをEqualに変更
  • InstructionSetとRegisterAndFlagNamesのハッシュ化

私の環境でのベンチマーク結果も参考に載せます。
あと、コミットには入れていませんが、dotnet 10にするとさらに10%程度早くなりました。
参考までにそのベンチマークも載せておきます。

また、お時間のあるときに、よろしくお願いいたします。

AILZ80ASM.Benchmark

dotnet 8

mainブランチ 既存速度

 // * Summary *

BenchmarkDotNet v0.13.12, Windows 11 (10.0.26200.7462)
13th Gen Intel Core i5-13400, 1 CPU, 16 logical and 10 physical cores
.NET SDK 10.0.101
  [Host]     : .NET 8.0.22 (8.0.2225.52707), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.22 (8.0.2225.52707), X64 RyuJIT AVX2


| Method     | Mean     | Error    | StdDev   |
|----------- |---------:|---------:|---------:|
| Benchmark1 | 698.7 ms | 13.69 ms | 15.77 ms |

// * Hints *
Outliers
  Benchmark.Benchmark1: Default -> 1 outlier  was  removed (760.11 ms)

// * Legends *
  Mean   : Arithmetic mean of all measurements
  Error  : Half of 99.9% confidence interval
  StdDev : Standard deviation of all measurements
  1 ms   : 1 Millisecond (0.001 sec)

// ***** BenchmarkRunner: End *****
Run time: 00:00:22 (22.86 sec), executed benchmarks: 1

Global total time: 00:00:40 (40.08 sec), executed benchmarks: 1
// * Artifacts cleanup *
Artifacts cleanup is finished


-----------------------------
修正版
commit: "eb8f5c22d50d1b487fff278924d2d1d4cfff4c94"

// * Summary *

BenchmarkDotNet v0.13.12, Windows 11 (10.0.26200.7462)
13th Gen Intel Core i5-13400, 1 CPU, 16 logical and 10 physical cores
.NET SDK 10.0.101
  [Host]     : .NET 8.0.22 (8.0.2225.52707), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.22 (8.0.2225.52707), X64 RyuJIT AVX2


| Method     | Mean     | Error    | StdDev  |
|----------- |---------:|---------:|--------:|
| Benchmark1 | 614.0 ms | 10.08 ms | 9.43 ms |

// * Legends *
  Mean   : Arithmetic mean of all measurements
  Error  : Half of 99.9% confidence interval
  StdDev : Standard deviation of all measurements
  1 ms   : 1 Millisecond (0.001 sec)

// ***** BenchmarkRunner: End *****
Run time: 00:00:19 (19.96 sec), executed benchmarks: 1

Global total time: 00:00:37 (37.21 sec), executed benchmarks: 1
// * Artifacts cleanup *
Artifacts cleanup is finished

dotnet 10

// * Summary *

BenchmarkDotNet v0.13.12, Windows 11 (10.0.26200.7462)
13th Gen Intel Core i5-13400, 1 CPU, 16 logical and 10 physical cores
.NET SDK 10.0.101
  [Host]     : .NET 10.0.1 (10.0.125.57005), X64 RyuJIT AVX2
  DefaultJob : .NET 10.0.1 (10.0.125.57005), X64 RyuJIT AVX2


| Method     | Mean     | Error    | StdDev   |
|----------- |---------:|---------:|---------:|
| Benchmark1 | 540.9 ms | 10.76 ms | 12.81 ms |

// * Hints *
Outliers
  Benchmark.Benchmark1: Default -> 1 outlier  was  removed, 2 outliers were detected (506.11 ms, 580.34 ms)

// * Legends *
  Mean   : Arithmetic mean of all measurements
  Error  : Half of 99.9% confidence interval
  StdDev : Standard deviation of all measurements
  1 ms   : 1 Millisecond (0.001 sec)

// ***** BenchmarkRunner: End *****
Run time: 00:00:21 (21.17 sec), executed benchmarks: 1

Global total time: 00:00:25 (25.56 sec), executed benchmarks: 1
// * Artifacts cleanup *
Artifacts cleanup is finished

Copilot AI review requested due to automatic review settings December 25, 2025 11:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes assembly speed by approximately 10% through performance improvements in string comparison operations. The changes replace inefficient LINQ operations with direct HashSet lookups and standardize string comparisons to use the more efficient string.Equals method.

  • Converted RegisterAndFlagNames and InstructionNames arrays to HashSet with case-insensitive comparer for O(1) lookup performance
  • Replaced string.Compare with string.Equals using StringComparison.OrdinalIgnoreCase for more efficient and clearer case-insensitive comparisons
  • Eliminated LINQ Where().Any() patterns in favor of direct HashSet.Contains() calls

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
AILZ80ASM/InstructionSet/Z80.cs Updated to use HashSet for RegisterAndFlagNames with case-insensitive comparer
AILZ80ASM/InstructionSet/InstructionSet.cs Changed RegisterAndFlagNames and InstructionNames from arrays to HashSets for faster lookups
AILZ80ASM/InstructionSet/ISA.cs Optimized IsMatchRegisterName and IsMatchInstructionName methods to use HashSet.Contains instead of LINQ Where + Any
AILZ80ASM/Assembler/AsmLoad.cs Replaced string.Compare with string.Equals in FindGlobalLabelName and FindLabels methods for improved performance

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AILight AILight changed the base branch from main to develop December 28, 2025 16:47
@AILight AILight changed the base branch from develop to main December 28, 2025 16:48
@AILight
Copy link
Owner

AILight commented Dec 28, 2025

ありがとうございます。1月にイベントがありそちらの準備でこちらまで手が回りませんので、申し訳ございませんが、1月中旬ぐらいに確認をさせていただきます。また、.NET 10化も計画しておりましたので、問題が発生しなければその時にあげたいと思います。

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