Skip to content

Singleton parser - how much the cost is when using multiple parse #2081

Answered by msujew
nguyen-vo asked this question in Q&A
Discussion options

You must be logged in to vote

So in case of the parser instance receives 2 concurrent requests with 2 different inputs wouldn't that causing a conflicts for the parser during parsing?

That's not possible in JavaScript, as the Chevrotain parser is synchronous, meaning it blocks the event loop while parsing any input. You cannot create concurrent parsers with Chevrotain, unless you create a worker thread (which in turn needs actually a new parser instance, as worker threads cannot share memory i.e. chevrotain parser objects).

If you need concurrency, I would recommend creating a thread pool the size of your CPU cores and instantiate a parser in each of them. That way you get the benefit of currency without requiring t…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@nguyen-vo
Comment options

@msujew
Comment options

msujew Dec 23, 2024
Collaborator

Answer selected by nguyen-vo
@nguyen-vo
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants