mybatis / mybatis-3

MyBatis SQL mapper framework for Java
http://mybatis.github.io/mybatis-3/
Apache License 2.0
19.72k stars 12.82k forks source link

Suspected high memory footprint #3183

Closed youngledo closed 3 months ago

youngledo commented 3 months ago

I have a sample project with more than 2000 tables. When I use Mybatis to load it, and then analyze dump through MAT tool, I find that the memory footprint is very high. Is this a normal phenomenon?

MyBatis version

3.x.x

Database vendor and version

mysql 8.0

Test case or example project

snapshot: image image image image

image image

demo2.zip: demo2.zip

MAT: https://eclipse.dev/mat/

harawata commented 3 months ago

Hello @youngledo ,

Well, if there are many mappers, MyBatis needs more memory to store them, obviously.

IIRC, sqlFragments are not necessary once all mappers are loaded, however, in the current design, developers can add mappers anytime they want (i.e. there is no "finished" state), so we cannot clear it automatically.

DefaultReflectorFactory has a flag classCacheEnabled that disables the internal cache, so you can give it a try if memory consumption is your biggest concern. It can have negative impact on execution speed, though.

If you find a place where MyBatis uses unnecessary memory, please let us know the details.