Skip to content

Support a Stream instead of string buffer #204

@rLindorfer

Description

@rLindorfer

Current Situtation

The Scanner class which is used to return tokens from the input buffer currently only accepts a string.

public Scanner(string buffer)
{
    Buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
    Cursor = new Cursor(Buffer, TextPosition.Start);
}

This means, if we read this stream from a blob or a file, we initially have to allocate the entire string in memory.

Problem

A huge buffer string will end up on the LOH (large object heap) which can lead to several memory and performance problems.
https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap

Solution

Use a generic Stream instead of a plain string. As a result, it would be possible to directly stream the buffer from a blob or a file.
As a result, it would for example be possible to implement a streaming support for parsing (Fluid) templates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions