I am implementing a (currently small) subset of a Prolog engine in Java. I am trying to speed up the unification of terms. Particularly, what concerns String comparisons.
My idea is to intern (by means of the String.intern()
method) all the strings representing atoms, so two atoms can be considered equals using reference comparison (==
) instead of invoking the String.equals()
method.
After reading the answers to similar questions in this site (e.g., When should we use intern method of String on String constants) these are my conclusions:
- I should gain on performance regarding atom comparisons.
- Memory footprint should also be a bit lower using the intern method.
- Atom instantiation may be slowed down a bit.
Is there a disadvantage I am not foreseen ? Or is there a better alternative to improve performance and reduce memory footprint in scenarios involving a big amount of data ?