You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Drop byte[] overloads across Tomlyn (lexer/parser/syntax/reader/serializer) to avoid implying native UTF-8 byte support
- Keep Stream overloads for convenient file IO (UTF-8 only) and clarify behavior in docs
- Remove Encoding.UTF8.GetString usage and obsolete UTF-8 decode helpers
|[`SyntaxParser.Parse(...)`](xref:Tomlyn.Parsing.SyntaxParser)| Tolerant - collects errors in `doc.Diagnostics`, always returns a tree. |
169
165
|[`SyntaxParser.ParseStrict(...)`](xref:Tomlyn.Parsing.SyntaxParser)| Strict - throws [`TomlException`](xref:Tomlyn.TomlException) on the first error. |
170
166
171
-
Both accept `string` and [`TomlLexer`](xref:Tomlyn.Parsing.TomlLexer) inputs. `Parse` also accepts `TextReader` and `byte[]`.
167
+
Both accept `string` and [`TomlLexer`](xref:Tomlyn.Parsing.TomlLexer) inputs. `Parse` also accepts `TextReader`.
Copy file name to clipboardExpand all lines: site/docs/performance.md
+14-5Lines changed: 14 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Performance
3
3
---
4
4
5
-
Tomlyn is designed for high throughput and low allocations.
5
+
Tomlyn is designed for high throughput and low allocations for **configuration-style** TOML workloads.
6
6
7
7
## Architecture
8
8
@@ -13,20 +13,29 @@ Tomlyn is designed for high throughput and low allocations.
13
13
|[`TomlSerializer`](xref:Tomlyn.TomlSerializer)| Reads directly from the parser stream when possible; source-generated metadata avoids reflection. |
14
14
|[`SyntaxParser`](xref:Tomlyn.Parsing.SyntaxParser)| Allocates tree nodes - use only when full-fidelity round-tripping is needed. |
15
15
16
+
## What “high-performance” means for Tomlyn
17
+
18
+
Tomlyn is optimized around the common TOML use-case: **configuration files** that can be loaded in memory.
19
+
Tomlyn is not a streaming parser and it does not aim to match the design goals of `System.Text.Json` for high-throughput web API scenarios.
20
+
21
+
Internally, Tomlyn parses a **UTF-16 `ReadOnlyMemory<char>`** view of the TOML payload.
22
+
This means that:
23
+
24
+
- Passing TOML as `string` is the most direct path.
25
+
- When you use `Stream` or `TextReader`, Tomlyn reads the entire payload into memory before parsing.
26
+
16
27
## Practical tips
17
28
18
29
| Tip | Why |
19
30
| --- | --- |
20
31
|**Cache [`TomlSerializerOptions`](xref:Tomlyn.TomlSerializerOptions)**| It is an immutable `sealed record`. Creating it once avoids repeated metadata resolution. |
21
32
|**Prefer source generation**|[`TomlSerializerContext`](xref:Tomlyn.Serialization.TomlSerializerContext) / [`TomlTypeInfo<T>`](xref:Tomlyn.TomlTypeInfo`1) avoids reflection, reduces startup, and is required for NativeAOT. |
|**Use `byte[]` overloads**|[`TomlSerializer.Deserialize<T>(byte[])`](xref:Tomlyn.TomlSerializer) avoids the `string` → `byte[]` conversion for pre-loaded data. |
33
+
|**Use `Stream`/`TextReader` for convenience**| Tomlyn reads the entire content into memory before parsing; use these overloads to integrate with existing IO code. |
24
34
|**Set `SourceName` once**| Attach it to cached options, not per-call - it doesn't affect parsing, only exception messages. |
25
35
|**Avoid [`SyntaxParser`](xref:Tomlyn.Parsing.SyntaxParser) for mapping**|[`SyntaxParser`](xref:Tomlyn.Parsing.SyntaxParser) builds a full tree. If you only need .NET objects, use [`TomlSerializer`](xref:Tomlyn.TomlSerializer) directly. |
26
36
27
37
> [!TIP]
28
-
> For the best performance, combine source generation with `Stream` or `byte[]` overloads.
29
-
> This gives you zero-reflection, zero-intermediate-string deserialization.
38
+
> For the best performance, combine source generation with a cached `TomlSerializerContext` and cached `TomlSerializerOptions`.
0 commit comments