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

Drop Async Implementation #9

Closed
Andrei15193 opened this issue May 23, 2020 · 2 comments
Closed

Drop Async Implementation #9

Andrei15193 opened this issue May 23, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Andrei15193
Copy link
Owner

Andrei15193 commented May 23, 2020

There is actually little need for async implementation of this library. The initial reasoning for this was to make it easy to keep an UI responsive when parsing a large text. This can easily be done using Task.Run() as such:

partial class MyForm
{
    // ...

    private void _ButtonClick(/* ... */)
    {
        Task.Run(
            () =>
            {
                var parser = new CreoleParser();
                var result = parser.Parse(MyText);
                var visitor = new MyCustomVisitor();
                result.Accept(visitor);
            }
        );
    }
}

And can be extended with CancellationToken to support cancellation:

partial class MyForm
{
    // ...

    private async void _ButtonClick(/* ... */)
    {
        using (CancellationTokenSource = new CancellationTokenSource())
            try
            {
                await Task.Run(
                    () =>
                    {
                        var parser = new CreoleParser();
                        var result = parser.Parse(MyText);
                        var visitor = new MyCustomVisitor(CancellationTokenSource.Token);
                        result.Accept(visitor);
                    },
                    CancellationTokenSource.Token
                );
            }
            catch (TaskCancelledException)
            {
                // ...
            }
        CancellationTokenSource = null;
    }

    private void _CancelButtonClick(/* ... */)
        => CancellationTokenSource?.Cancel();
}

In addition to having a synchronous implementation, this can make it easier for the parser to be ported to other languages with more ease (e.g.: JavaScript). While it is questionable whether an async implementation works better in that case, since JS is single-threaded, and chopping the execution into multiple methods can have a small impact on performance (context switching) but allows the UI to still be responsive as it can handle callbacks in between the chopped methods.

In this case the parsing can be delegated to a back-end (in case of very large text fields) and for relatively small or medium amounts of text the parser to be fast enough to transform the text without having a visible impact on the user experience. In the latter case some benchmarks would be useful to know appropriate limits where the parser may start to take a longer time to process considering multiple cases: simple text, moderate rich text (not a lot of rich text elements, something that would be expected), most difficult rich text the parser has to handle all put together (worst case scenario). This benchmark should help provide some useful information about what the limits are and whether it is acceptable for the user to have have these potential lags. It should cover multiple devices from low-end smartphones to high-end ones, tablets, laptops and PCs.

@Andrei15193 Andrei15193 added the enhancement New feature or request label May 23, 2020
@Andrei15193 Andrei15193 self-assigned this May 23, 2020
@Andrei15193 Andrei15193 added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels May 24, 2020
@Andrei15193
Copy link
Owner Author

Andrei15193 commented May 24, 2020

In addition to having a synchronous implementation, this can make it easier for the parser to be ported to other languages with more ease (e.g.: JavaScript). While it is questionable whether an async implementation works better in that case, since JS is single-threaded, and chopping the execution into multiple methods can have a small impact on performance (context switching) but allows the UI to still be responsive as it can handle callbacks in between the chopped methods.

In this case the parsing can be delegated to a back-end (in case of very large text fields) and for relatively small or medium amounts of text the parser to be fast enough to transform the text without having a visible impact on the user experience. In the latter case some benchmarks would be useful to know appropriate limits where the parser may start to take a longer time to process considering multiple cases: simple text, moderate rich text (not a lot of rich text elements, something that would be expected), most difficult rich text the parser has to handle all put together (worst case scenario). This benchmark should help provide some useful information about what the limits are and whether it is acceptable for the user to have have these potential lags. It should cover multiple devices from low-end smartphones to high-end ones, tablets, laptops and PCs.

Should be treated in a separate issue with help wanted label.

Andrei15193 added a commit that referenced this issue May 24, 2020
Andrei15193 added a commit that referenced this issue May 24, 2020
@Andrei15193
Copy link
Owner Author

In addition to having a synchronous implementation, this can make it easier for the parser to be ported to other languages with more ease (e.g.: JavaScript). While it is questionable whether an async implementation works better in that case, since JS is single-threaded, and chopping the execution into multiple methods can have a small impact on performance (context switching) but allows the UI to still be responsive as it can handle callbacks in between the chopped methods.
In this case the parsing can be delegated to a back-end (in case of very large text fields) and for relatively small or medium amounts of text the parser to be fast enough to transform the text without having a visible impact on the user experience. In the latter case some benchmarks would be useful to know appropriate limits where the parser may start to take a longer time to process considering multiple cases: simple text, moderate rich text (not a lot of rich text elements, something that would be expected), most difficult rich text the parser has to handle all put together (worst case scenario). This benchmark should help provide some useful information about what the limits are and whether it is acceptable for the user to have have these potential lags. It should cover multiple devices from low-end smartphones to high-end ones, tablets, laptops and PCs.

Should be treated in a separate issue with help wanted label.

Done, created #13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant