简体   繁体   中英

ANTLR4 Memory Usage

When using ANTLR4, it seems that a lot of memory is allocated in 【antlr.NewBaseATNConfig】. Google's suggestion is to use 【ParserATNSimulator.clearDFA】, But this function has been moved out.

If the performance requirements are not high, is there any way to reduce the memory usage of ANTLR4?

Clearing the DFA will help only temporary. The ATNConfig instances are used to optimize the parsing process and are automatically created during parsing whenever a new path through the ATN was taken to parse a specific input. They are reused when the same path is taken again later and they are shared between parser instances to optimize all parser invocations.

The only way I see to keep memory footprint low is to keep the grammar as simple as possible and parse only small snippets, which don't vary much.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM