antlr / antlr/antlr4

[Cpp] performance issue in class SingleWriteMultipleReadLock

Open
#2,002 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

Dear all,

I use ANTLR 4.7 CPP target for my grammar.
I identified a sever performance issue with class SingleWriteMultipleReadLock (maybe also referring to issue #1435 )
When running the parser with 4 threads on a 2 core machine I see an increase of parse time from below 1 sec to over 20 sec for one file to parse.

My Profiler run shows that the issues seems to be the mutex used in class SingleWriteMultipleReadLock which is used in LexerATNSimulator::getExistingTargetState

The calls of _edgeLock.readLock(); and _edgeLock.readUnlock(); seem to consume over 80 % of the parse time in my scenario.

Does anyone have an idea how to optimize this?

Since my application is only running on Windows I were thinking of replacing the std::mutex by a Windows Critical Section which should be a lot faster. But maybe there are better ways to speed this up.

Thanks for any suggestion.

Regards,
Christian

Contributor guide

Open the contributing guide

Research direction

Read the C++ target's SingleWriteMultipleReadLock and its use in LexerATNSimulator::getExistingTargetState, then profile the _edgeLock.readLock() and readUnlock() calls under the reported four-thread workload. Compare the current std::mutex behavior with the proposed Windows Critical Section or another approach; done means the parsing slowdown is measurably improved without breaking concurrent parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.