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

Reduce substring allocations #189

Merged
merged 29 commits into from
Aug 27, 2021

Conversation

axunonb
Copy link
Member

@axunonb axunonb commented Aug 27, 2021

Target frameworks

  • Changed netstandard2.0 to netstandard2.1.
  • net461 support unchanged.
  • Added package System.Memory

Remove repetitive substring allocations

Connected modifications:

  • Added method Write(ReadOnlySpan<char> text) to IFormattingInfo
  • Generated substrings are cached in classes Format, FormatItem, LiteralText, Placeholder and Selector.
  • Evaluating escaped characters for Placeholder.FormatterOptions and LiteralText work without heap memory allocation.

Alignment operator inheritance is optimized

  • Alignment implementation introduced with PR #174 is modified for better performance
  • Added method Placeholder.AddSelector
  • Placeholder.Selectors is now internal. Selectors are accessible with IReadOnlyList<Selector> Placeholder.GetSelectors().

DictionarySource performance improved

  • Implemented suggestion in issue #186 for better speed and less GC pressure.
  • Side effect: We're using the CaseSensitivityType of the dictionary for getting the value for a key. Settings.GetCaseSensitivityComparison() will not be applied.

axunonb and others added 28 commits April 17, 2021 10:25
* Alignment operator inheritance is optimized
* DictionarySource performance improved
@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #189 (2c362c7) into version/v3.0 (4565ef7) will decrease coverage by 0%.
The diff coverage is 91%.

❗ Current head 2c362c7 differs from pull request most recent head 47cb135. Consider uploading reports for the commit 47cb135 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           version/v3.0   #189   +/-   ##
===========================================
- Coverage            95%    95%   -0%     
===========================================
  Files                49     50    +1     
  Lines              2019   2050   +31     
===========================================
+ Hits               1910   1939   +29     
- Misses              109    111    +2     
Impacted Files Coverage Δ
src/SmartFormat/Core/Output/NullOutput.cs 0% <0%> (ø)
src/SmartFormat/Core/Output/TextWriterOutput.cs 71% <0%> (ø)
src/SmartFormat/Core/Parsing/Placeholder.cs 85% <85%> (+12%) ⬆️
src/SmartFormat/Core/Formatting/FormattingInfo.cs 100% <100%> (+8%) ⬆️
src/SmartFormat/Core/Output/StringOutput.cs 100% <100%> (ø)
src/SmartFormat/Core/Parsing/EscapedLiteral.cs 100% <100%> (ø)
src/SmartFormat/Core/Parsing/Format.cs 84% <100%> (+1%) ⬆️
src/SmartFormat/Core/Parsing/FormatItem.cs 63% <100%> (+2%) ⬆️
src/SmartFormat/Core/Parsing/LiteralText.cs 100% <100%> (ø)
src/SmartFormat/Core/Parsing/Parser.cs 93% <100%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4565ef7...47cb135. Read the comment docs.

@axunonb axunonb merged commit 38b7355 into axuno:version/v3.0 Aug 27, 2021
@axunonb axunonb deleted the reduce-substring-allocations branch August 27, 2021 11:49
axunonb added a commit that referenced this pull request Aug 27, 2021
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
#### Target frameworks

* Changed `netstandard2.0` to `netstandard2.1`.
* `net461` support unchanged.
* Added package `System.Memory`

#### Remove repetitive substring allocations

Connected modifications:

* Added method `Write(ReadOnlySpan<char> text)` to `IFormattingInfo`
* Generated substrings are cached in classes `Format`, `FormatItem`, `LiteralText`, `Placeholder` and `Selector`.
* Evaluating escaped characters for `Placeholder.FormatterOptions` and `LiteralText` work without heap memory allocation.

#### Alignment operator inheritance is optimized

* Alignment implementation introduced with PR [axuno#174](axuno#174) is modified for better performance
* Added method `Placeholder.AddSelector`
* `Placeholder.Selectors` is now internal. Selectors are accessible with `IReadOnlyList<Selector> Placeholder.GetSelectors()`.

#### DictionarySource performance improved

* Implemented suggestion in issue [axuno#186](axuno#186) for better speed and less GC pressure.
* Side effect: We're using the `CaseSensitivityType` of the dictionary for getting the value for a key. `Settings.GetCaseSensitivityComparison()` will not be applied.
axunonb added a commit to axunonb/SmartFormat that referenced this pull request Mar 10, 2022
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

1 participant