Skip to content

Use memory more efficiently when reading files, serialising and deserialising - #9

Merged
kristiker merged 16 commits into
full-sourcegenfrom
memory-efficiency
Sep 8, 2026
Merged

Use memory more efficiently when reading files, serialising and deserialising#9
kristiker merged 16 commits into
full-sourcegenfrom
memory-efficiency

Conversation

@Angel-foxxo

Copy link
Copy Markdown
Collaborator

Makes attributes a 40 byte slot with an inline value union, one array per element, instead of an OrderedDictionary of attribute objects with boxed values

Arrays are now slices of 1 MB chunks on the large object heap, read with one copy, instead of a List filled one boxed item at a time

Elements live in a generic dictionary and list under one lock, sized from the file, with IDs generated on first use

Typed loading assigns class properties through typed bindings, without boxing

Saving gathers strings and element order in one pass, writes from the slots without boxing, writes value arrays in one piece and buffers the output

Adds a general AttributeType enum, named after valve's DmAttributeType_t

Comment thread Datamodel.NET/AttributeList.cs Outdated
Comment on lines +23 to +24
/// <summary>The value has not been read from the stream yet; <see cref="InlineValue.Ticks"/> holds the position it starts at.</summary>
Deferred,

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.

What does ticks means, i'd expect 'offset'. @copilot what you think

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good call, added Offset as an alias field (same union slot) on InlineValue and switched the Deferred slot usage to it in 5dc983d, keeping Ticks only for the Time case.

@kristiker kristiker Sep 8, 2026

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.

Remove comment above fieldoffset

Change library version to 2.0-beta

@copilot

Co-authored-by: kristiker <26466974+kristiker@users.noreply.github.com>
@kristiker
kristiker merged commit c4f3082 into master Sep 8, 2026
4 checks passed
@kristiker
kristiker deleted the memory-efficiency branch September 8, 2026 21:41
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