Skip to content

Conversation

@luoluoyuyu
Copy link
Member

@luoluoyuyu luoluoyuyu commented Dec 5, 2025

Description

The initialization cost of the TypeManager in StatementAnalyzer is too high. The TypeManager can be placed in the Coordinator to reduce unnecessary object creation.
img_v3_02sm_830657ac-e4fc-446f-a77f-13a7596c404g
img_v3_02sm_ad3fc8e6-93d3-4127-ab49-f15ca2aa977g


This PR has:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious
    for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold
    for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR

…to avoid frequent object creation

Problem:
- Every time a SQL statement is analyzed, a new StatementAnalyzer instance is created
- Each StatementAnalyzer instance creates a new InternalTypeManager object
- InternalTypeManager initialization involves creating a ConcurrentHashMap and populating it with 11 type mappings
- This happens for EVERY query, causing unnecessary object allocation and GC pressure

Analysis:
- InternalTypeManager is thread-safe (uses ConcurrentHashMap)
- After construction, the type mappings are immutable (read-only)
- All StatementAnalyzer instances use the same type mappings
- No instance-specific state in InternalTypeManager

Solution:
- Changed 'private final TypeManager typeManager' to 'private final static TypeManager TYPE_MANAGER'
- This ensures only ONE InternalTypeManager instance is created for the entire application
- All StatementAnalyzer instances now share the same TYPE_MANAGER instance

Performance Impact:
- Reduces object allocation for every SQL query
- Decreases GC pressure, especially under high query load
- Saves memory by eliminating duplicate type mapping storage
- No functional changes or thread-safety concerns
每次执行SQL查询时都会创建新的StatementAnalyzer实例,导致频繁创建InternalTypeManager对象。
InternalTypeManager是线程安全且不可变的,可以安全地作为静态变量共享。

优化:
- 将typeManager从实例变量改为静态变量TYPE_MANAGER
- 避免每次查询都创建新的InternalTypeManager实例
- 减少对象分配和GC压力

性能影响:
- 减少内存分配
- 降低高并发查询场景下的GC压力
- 无功能变更,线程安全
Copy link
Collaborator

@Caideyipi Caideyipi left a comment

Choose a reason for hiding this comment

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

LGTM

@JackieTien97 JackieTien97 merged commit 1b2b32b into apache:master Dec 5, 2025
27 of 28 checks passed
JackieTien97 pushed a commit that referenced this pull request Dec 8, 2025
JackieTien97 pushed a commit that referenced this pull request Dec 9, 2025
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