Skip to content

General library improvements#17

Open
RelaxSpirit wants to merge 30 commits into
nanoframework:mainfrom
RelaxSpirit:imp_proc_speed
Open

General library improvements#17
RelaxSpirit wants to merge 30 commits into
nanoframework:mainfrom
RelaxSpirit:imp_proc_speed

Conversation

@RelaxSpirit

@RelaxSpirit RelaxSpirit commented Feb 3, 2026

Copy link
Copy Markdown
Collaborator

Description

  1. Fixed a typo in the internal method name 'GetMassagePackObjectTokens'.
  2. The for loop has been simplified to while where possible.
  3. Direct comparison of types when searching for converters.
  4. Properties are extracted from types in a separate class.
  5. Improved retrieval of an object by MessagePack data type.
  6. Duplicate and unused code has been removed.
  7. Improved information about MessagePack data type errors in converters.
  8. Add new Unit test for inherited classes.
  9. Added new type compare benchmark.
  10. The data for comparing serialization and deserialization speeds has been replaced with more relevant data.
  11. Updated with benchmark results (README).

Motivation and Context

Using the library showed that the deserialization time is significantly different from the serialization time.
Performance measurements revealed a number of places with suboptimal code:

  1. Comparison of types for converters by FullName type hash code. Direct type comparison is faster.
  2. Many conditions when defining MessagePack tokens. MessagePack DataTypes can be divided into groups and processed separately.
  3. Due to the way nanoFramework works reflection with properties, each property is processed twice in the loop, for set and get, and is covered by an additional condition.
  4. Standard converters do not have specific exceptions for errors in processing objects passed for conversion (invalid type, null).
  5. The solution contains unused and duplicate code. This affects the total size of the library in mcu memory.
  6. The benchmark test object is not entirely relevant.
  7. There is no unit test for classes with property inheritance.

How Has This Been Tested?

Tested with all existing tests in the solution + a new one has been added.

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

RelaxSpirit and others added 10 commits December 30, 2025 00:18
Correction based on Copilot's comments
perf(Simplified the cycle in the method 'ReadMap')
perf(Duplicate error message lines have been removed)
perf(Properties are extracted from types in a separate class);
perf(Improved retrieval of an object by MessagePack data type);
perf(Duplicate and unused code has been removed);
perf(Improved information about MessagePack data type errors in converters);
perf(The data for comparing serialization and deserialization speeds has been replaced with more relevant data);
@nfbot

nfbot commented Feb 3, 2026

Copy link
Copy Markdown
Member

@RelaxSpirit I've fixed the checklist for you.
FYI, the correct format is [x], no spaces inside brackets, no other chars.

@coderabbitai

coderabbitai Bot commented Feb 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (57)
  • README.md is excluded by !**/*.md and included by none
  • Shared/MessagePack/ConverterContext.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/ArrayConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/ArrayListConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/BinaryConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/BoolConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/ByteConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/CharConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/DateTimeConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/DoubleConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/FloatConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/GuidConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/IntConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/LongConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/MapConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/SbyteConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/ShortConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/SimpleArrayConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/StringConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/TimeSpanConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/UintConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/UlongConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Converters/UshortConverter.cs is excluded by none and included by none
  • Shared/MessagePack/Dto/ArraySegment.cs is excluded by none and included by none
  • Shared/MessagePack/Dto/MemberMapping.cs is excluded by none and included by none
  • Shared/MessagePack/Dto/MemberPropertyInfo.cs is excluded by none and included by none
  • Shared/MessagePack/Dto/TypeValueDictionary.cs is excluded by none and included by none
  • Shared/MessagePack/Exceptions/ConverterNotFoundException.cs is excluded by none and included by none
  • Shared/MessagePack/Extensions/DataTypesExtension.cs is excluded by none and included by none
  • Shared/MessagePack/Extensions/NumberConverterHelper.cs is excluded by none and included by none
  • Shared/MessagePack/Extensions/ObjectTokenHelper.cs is excluded by none and included by none
  • Shared/MessagePack/MessagePack.projitems is excluded by none and included by none
  • Shared/MessagePack/MessagePackSerializer.cs is excluded by none and included by none
  • Shared/MessagePack/Stream/BaseReader.cs is excluded by none and included by none
  • Shared/MessagePack/Stream/MemoryStreamReader.cs is excluded by none and included by none
  • Shared/MessagePack/Stream/MemoryStreamWriter.cs is excluded by none and included by none
  • Shared/MessagePack/Utility/ExceptionUtility.cs is excluded by none and included by none
  • Shared/MessagePack/Utility/FieldUtility.cs is excluded by none and included by none
  • Shared/MessagePack/Utility/PropertyUtility.cs is excluded by none and included by none
  • UnitTestShared/Helpers/TestsHelper.cs is excluded by none and included by none
  • UnitTestShared/TestData/SecureMessageConverter.cs is excluded by none and included by none
  • UnitTestShared/TestData/TestBaseClass.cs is excluded by none and included by none
  • UnitTestShared/TestData/TestInheritorClass.cs is excluded by none and included by none
  • UnitTestShared/UnitTestShared.projitems is excluded by none and included by none
  • UnitTestShared/UnitTests.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/Base/BaseIterationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/Data/ComparativeTestObjects.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/Data/ReferenceTestObjects.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/DeserializationBenchmarks/ComparativeDeserializationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/DeserializationBenchmarks/ReferenceTypesDeserializationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/DeserializationBenchmarks/ValueTypesDeserializationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/Program.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/SerializationBenchmarks/ComparativeSerializationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/SerializationBenchmarks/ReferenceTypesSerializationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/SerializationBenchmarks/ValueTypesSerializationBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/TypeCompareBenchmark.cs is excluded by none and included by none
  • nanoFramework.MessagePack.Benchmark/nanoFramework.MessagePack.Benchmark.nfproj is excluded by none and included by none

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@josesimoes

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@josesimoes josesimoes requested a review from Copilot February 18, 2026 14:54
@josesimoes

Copy link
Copy Markdown
Member

@RelaxSpirit thank you for improving the library. In the future, please make smaller PRs with targeted changes (like moving all using declaration to the top of the files). It makes so much easier to review then. Bulk changes make it harder to review. In case there are many PRs in the same batch, it's OK to have a working branch and PR against it. When completed, we can merge the branch into main. 😉

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements a comprehensive set of improvements to the nanoFramework MessagePack library focused on performance optimization and code quality. The PR addresses performance bottlenecks identified through profiling, including inefficient type comparisons, redundant reflection operations, and suboptimal data type handling.

Changes:

  • Refactored type comparison from hash code-based to direct type comparison for better performance
  • Optimized MessagePack data type handling with grouped processing and delegation pattern
  • Extracted property handling logic into a dedicated MemberPropertyInfo class for nanoFramework
  • Enhanced error messages in converters with specific type information
  • Added unit tests for class inheritance scenarios and type comparison benchmarks
  • Updated benchmark test data to more realistic scenarios and added comprehensive device-specific results

Reviewed changes

Copilot reviewed 57 out of 57 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
TypeCompareBenchmark.cs New benchmark comparing type comparison methods (hash vs direct)
ComparativeTestObjects.cs Replaced complex nested test object with simpler, more realistic benchmark data
Program.cs Enhanced benchmark output with device-specific information and improved formatting
BaseIterationBenchmark.cs Centralized iteration count logic based on device type (virtual vs physical)
TestInheritorClass.cs, TestBaseClass.cs New test classes for validating property inheritance serialization
UnitTests.cs Added test for inherited class serialization/deserialization
PropertyUtility.cs Refactored to use new MemberPropertyInfo class for nanoFramework property extraction
FieldUtility.cs Improved null handling and code clarity
ExceptionUtility.cs Consolidated number serialization exceptions and improved error messages
MemberPropertyInfo.cs New class extracting property information from MethodInfo in nanoFramework
TypeValueDictionary.cs New type-keyed dictionary replacing Hashtable for converter storage
MemberMapping.cs Simplified property/field handling with clearer API
MemoryStreamReader.cs Added leaveOpen parameter for stream disposal control
MessagePackSerializer.cs Added leaveOpen parameter to Deserialize method
All Converters Added null/type validation, improved error messages, removed duplicate code
ObjectTokenHelper.cs Fixed typo in method name (GetMassagePackObjectTokens → GetMessagePackObjectTokens)
NumberConverterHelper.cs Removed redundant helper methods, simplified byte value handling
ConverterContext.cs Replaced Hashtable with TypeValueDictionary, optimized data type handling with delegation pattern
README.md Updated with new benchmark results across multiple devices

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

Comment thread Shared/MessagePack/Converters/UlongConverter.cs Outdated
Comment thread Shared/MessagePack/Converters/UintConverter.cs Outdated
Comment thread Shared/MessagePack/Converters/DoubleConverter.cs Outdated
Comment thread nanoFramework.MessagePack.Benchmark/Program.cs
Comment thread Shared/MessagePack/Converters/SimpleArrayConverter.cs Outdated
Comment thread README.md Outdated
Comment thread nanoFramework.MessagePack.Benchmark/TypeCompareBenchmark.cs Outdated
Comment thread Shared/MessagePack/Dto/MemberPropertyInfo.cs Outdated
Comment thread Shared/MessagePack/Dto/MemberMapping.cs
Comment thread Shared/MessagePack/Converters/UshortConverter.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@josesimoes josesimoes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@RelaxSpirit please address Copilot review comments. If you disagree with something, let's discuss it.

RelaxSpirit and others added 6 commits February 18, 2026 21:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
RelaxSpirit and others added 13 commits February 18, 2026 21:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@RelaxSpirit

Copy link
Copy Markdown
Collaborator Author

@josesimoes Please forgive me for such a big PR.
Once I started optimizing, I couldn't stop. :)
And the edits were too interconnected.

I corrected all of the Copilot comments and what he missed.

@RelaxSpirit RelaxSpirit left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Corrections based on Copilot comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants