Skip to content

Commit 017121b

Browse files
committed
Commit from GitHub Actions (Reduce Adoc)
1 parent 8b13809 commit 017121b

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

README-EN.adoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,43 @@ You can cache scripts before first execution using the following method to ensur
620620

621621
Note that this cache has an unlimited size; be sure to control its size in your application. You can periodically clear the compilation cache by calling the `clearCompileCache` method.
622622

623+
=== Clearing DFA Cache
624+
625+
QLExpress uses ANTLR4 as its parsing engine. ANTLR4 builds a DFA (Deterministic Finite Automaton) cache at runtime to accelerate subsequent syntax parsing. This cache consumes a certain amount of memory.
626+
627+
In some memory-sensitive scenarios, you can call the `clearDFACache` method to clear the DFA cache and release memory.
628+
629+
> **IMPORTANT WARNING**: Clearing the DFA cache will cause a significant compilation performance degradation. It is NOT recommended for normal use cases.
630+
631+
==== Use Cases
632+
633+
* **Memory-sensitive applications**: When memory usage is a critical concern and you can tolerate slower compilation times
634+
* **Infrequently changing scripts**: When scripts are relatively stable and not frequently recompiled
635+
636+
==== Best Practice
637+
638+
Call this method immediately after parsing and caching your expression, and ensure all subsequent executions use the cached option to avoid recompilation. Example code:
639+
640+
[source,java,indent=0]
641+
----
642+
/*
643+
* When the expression changes, parse it and add it to the expression cache;
644+
* after parsing is complete, call clearDFACache.
645+
*/
646+
Express4Runner runner = new Express4Runner(InitOptions.DEFAULT_OPTIONS);
647+
runner.parseToDefinitionWithCache(exampleExpress);
648+
runner.clearDFACache();
649+
650+
/*
651+
* All subsequent runs of this script must enable the cache option to ensure that re-compilation does not occur.
652+
*/
653+
for (int i = 0; i < 3; i++) {
654+
runner.execute(exampleExpress, Collections.emptyMap(), QLOptions.builder().cache(true).build());
655+
}
656+
----
657+
658+
By following this approach, you can minimize memory usage while maintaining performance.
659+
623660
=== Setting Timeout
624661

625662
You can set a timeout for scripts to prevent infinite loops or other reasons from causing excessive consumption of application resources.

README.adoc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,43 @@ QLExpress4 支持通过自定义 `ClassSupplier` 来指定类加载器,这在
621621

622622
注意该缓存的大小是无限的,业务上注意控制大小,可以调用 `clearCompileCache` 方法定期清空编译缓存。
623623

624+
=== 清除 DFA 缓存
625+
626+
QLExpress 使用 ANTLR4 作为解析引擎,ANTLR4 在运行时会构建 DFA (确定有限状态自动机) 缓存来加速后续的语法解析。这个缓存会占用一定的内存空间。
627+
628+
在某些内存敏感的场景下,可以通过调用 `clearDFACache` 方法来清除 DFA 缓存,释放内存。
629+
630+
> **重要警告**: 清除 DFA 缓存会导致编译性能大幅下降,正常情况下不建议使用此方法。
631+
632+
==== 适用场景
633+
634+
* **内存敏感型应用**: 当内存使用是关键考虑因素,且可以容忍较慢的编译时间时
635+
* **脚本不经常变更**: 当脚本相对稳定且不会频繁重新编译时
636+
637+
==== 最佳实践
638+
639+
在解析并缓存表达式后立即调用此方法,并确保后续所有执行都打开缓存选项以避免重新编译。示例代码如下:
640+
641+
[source,java,indent=0]
642+
----
643+
/*
644+
* When the expression changes, parse it and add it to the expression cache;
645+
* after parsing is complete, call clearDFACache.
646+
*/
647+
Express4Runner runner = new Express4Runner(InitOptions.DEFAULT_OPTIONS);
648+
runner.parseToDefinitionWithCache(exampleExpress);
649+
runner.clearDFACache();
650+
651+
/*
652+
* All subsequent runs of this script must enable the cache option to ensure that re-compilation does not occur.
653+
*/
654+
for (int i = 0; i < 3; i++) {
655+
runner.execute(exampleExpress, Collections.emptyMap(), QLOptions.builder().cache(true).build());
656+
}
657+
----
658+
659+
通过这种方式,可以在保证性能的同时,最大限度地降低内存占用。
660+
624661
=== 设置超时时间
625662

626663
可以给脚本设置一个超时时间,防止其中存在死循环或者其他原因导致应用资源被过量消耗。

0 commit comments

Comments
 (0)