12

We are trying to improve performance in our Java application. While using the Memory Analysis tool, I noticed that there are many duplicate Strings that seem to have originated in Hibernate. For example, the Memory Analysis Tool sees over 6000 occurrences of "rowid_0_" and "0_", and tracing to the GC root shows Hibernate's involvement:

enter image description here

It seems as though we could improve performance if we could intern those Strings. If it were "our" code, I could modify it and see the effects. Is there any way that I can coerce Hibernate into using interned Strings?

7
  • 1
    What version of Hibernate are you using? I don't see any new String() in org.hibernate.loader.DefaultEntityAliases. If anything it does intern strings. grepcode.com/file/repository.springsource.com/org.hibernate/… Commented Feb 25, 2014 at 17:02
  • @Steve Kuo - We are using hibernate-core 3.6.10.Final and hibernate-jpa-2.0-api. Could it be a JPA thing? Commented Feb 25, 2014 at 17:56
  • 1
    @Steve Kuo - On line 87 of the link you provided, I see "rowIdAlias = Loadable.ROWID_ALIAS + suffix;". This may be a culprit. Commented Feb 25, 2014 at 18:19
  • Yup I see it now, and StringBuilder does indeed create a new String. Commented Feb 25, 2014 at 19:10
  • Is 6000 extra string objects that big a deal? Commented Feb 26, 2014 at 22:17

1 Answer 1

1

I now see that the Hibernate issue 3924 refers to this. However, HHH-3924 has a status of "Open", and is unresolved. It does refer to a code patch that interns the rowid Strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.