You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2016/12/06 12:43:00 UTC
incubator-unomi git commit: New segment update optimization,
hopefully will work better than the last one.
Repository: incubator-unomi
Updated Branches:
refs/heads/feature-UNOMI-28-ES2X 2263da963 -> d7a796957
New segment update optimization, hopefully will work better than the last one.
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/d7a79695
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/d7a79695
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/d7a79695
Branch: refs/heads/feature-UNOMI-28-ES2X
Commit: d7a7969578817eebf7a72c0c364200f0f084bb10
Parents: 2263da9
Author: Serge Huber <sh...@apache.org>
Authored: Tue Dec 6 13:42:54 2016 +0100
Committer: Serge Huber <sh...@apache.org>
Committed: Tue Dec 6 13:42:54 2016 +0100
----------------------------------------------------------------------
.../services/services/SegmentServiceImpl.java | 26 +++++++++++++++++---
1 file changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/d7a79695/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
index d1f120f..3a64be1 100644
--- a/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/services/SegmentServiceImpl.java
@@ -831,10 +831,28 @@ public class SegmentServiceImpl implements SegmentService, SynchronousBundleList
List<Profile> previousProfiles = persistenceService.query(segmentCondition, null, Profile.class);
List<Profile> newProfiles = persistenceService.query(segment.getCondition(), null, Profile.class);
- Set<Profile> profilesToAdd = new HashSet<>(newProfiles);
- Set<Profile> profilesToRemove = new HashSet<>(previousProfiles);
- profilesToAdd.removeAll(previousProfiles);
- profilesToRemove.removeAll(newProfiles);
+ // we use sets instead of lists to speed up contains() calls that are very expensive on lists.
+
+ // we use to use removeAll calls but these are expensive because they require lots of copies upon element
+ // removal so we implemented them with adds instead.
+ //profilesToAdd.removeAll(previousProfiles);
+ //profilesToRemove.removeAll(newProfiles);
+
+ Set<Profile> newProfilesSet = new HashSet<>(newProfiles);
+ Set<Profile> previousProfilesSet = new HashSet<>(previousProfiles);
+ Set<Profile> profilesToAdd = new HashSet<>(newProfilesSet.size() / 2);
+ for (Profile newProfile : newProfilesSet) {
+ if (!previousProfilesSet.contains(newProfile)) {
+ profilesToAdd.add(newProfile);
+ }
+ }
+ Set<Profile> profilesToRemove = new HashSet<>(previousProfilesSet.size() / 2);
+ for (Profile previousProfile : previousProfilesSet) {
+ if (!newProfilesSet.contains(previousProfile)) {
+ profilesToRemove.add(previousProfile);
+ }
+ }
+
for (Profile profileToAdd : profilesToAdd) {
profileToAdd.getSegments().add(segment.getItemId());