improve performance of session.clear()

Description

Clearing a session that contains a large number of Proxies takes a very long time. The reason for this is that null is set on the LazyInitializer when clearing the StatefulPersistenceContext, whenever a new session is set on an AbstractLazyInitializer, a check is done to see if the AbstractLazyInitializer is still attached to its previous session (and correctly throws an exception if it is). This check performs a linear search through all Proxies in the PersistenceContext. Since we're setting the session to null, do we really need to do this expensive linear search?
I propose we not perform the linear search if the session being set on the AbstractLazyInitializer is null.

Environment

None

Activity

Show:
Alex Pires de Camargo
November 5, 2008, 4:26 PM

Its not just a performance improvement, the fix for generated this exponential search on clear (its linear for evict, exponential for clear). Session.clear should not take minutes to run in session with many proxies opened, in 3.2.3 or previous takes no time.

I would open a bug for this, but as you have already reported the problem, I found better to add more info to your report. If you prefer I can open another ticket.

Steve Ebersole
January 7, 2009, 5:18 PM

It is an improvement

Steve Ebersole
January 7, 2009, 6:18 PM

Could one of y'all test this please?

Alex Pires de Camargo
January 14, 2009, 6:33 PM

Tested with sucess!

Steve Ebersole
February 3, 2009, 3:17 AM

Thanks for following up Alex.

Fixed

Assignee

Steve Ebersole

Reporter

Jay Erb

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major