Skip to content

Conversation

@TIHan
Copy link
Contributor

@TIHan TIHan commented Dec 30, 2019

We were getting a ton of TokenTup allocations when parsing.

Image below is just a small sample of allocations of parsing one file, TypeChecker.fs.
Untitled3

There are never many TokenTup objects being used at the same time. They are created and thrown away very quickly. But, they are very large.

To handle this problem, we can use an object pool. Below is the impact it had.

Before:
Untitled (Recovered)2

After:
Untitled2

Makes the parser faster and doesn't push objects into Gen2 so quickly. The downside is that we have to care about the lifetime of TokenTup in the LexFilter, so it increases complexity and more prone to error - but should be caught quickly.

Alternatives:

  • Make TokenTup a struct.
    • Making TokenTup a struct may eliminate heap allocations, but there are a ton of copying. To fix that problem we could pass it byref. However, this requires much larger changes and ergonomically speaking, is a lot harder to deal with.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

Great approach overall and love the results. Some minor things + a question.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

Awesome work and love the results.

@cartermp cartermp mentioned this pull request Dec 31, 2019
10 tasks
@cartermp cartermp merged commit 99c5a49 into dotnet:master Jan 6, 2020
@cartermp cartermp mentioned this pull request Jan 17, 2020
5 tasks
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
…lter (dotnet#8058)

* not working

* more fixes

* fix

* a change

* Pool now works in lex filter

* Added checks

* Added comment to maxSize

* Minor comment on TokenTup
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.

4 participants