-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize bulk operations within EntityCache #1133
* Compilation fixed after merging master * Make `EntityCache.data` public as it is widely used to re-init EntityCache * Selectively remove referrers and references * Restrict access to cache internals * Rotate referrer cache to create more O(1) ops * Optimize bulk updates Joel Feinstein * Ignore jetbrains.db Joel Feinstein * Optimize inserts using identity hash set
- Loading branch information
1 parent
6fd6d98
commit ad89245
Showing
8 changed files
with
161 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
out/ | ||
build/ | ||
classes/ | ||
**/jetbrains.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
exposed-dao/src/main/kotlin/org/jetbrains/exposed/dao/LinkedIdentityHashSet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.jetbrains.exposed.dao | ||
|
||
import java.util.* | ||
|
||
internal class LinkedIdentityHashSet<T> : MutableSet<T> { | ||
private val set: MutableSet<T> = Collections.newSetFromMap(IdentityHashMap()) | ||
private val list: MutableList<T> = LinkedList() | ||
|
||
override fun add(element: T): Boolean { | ||
return set.add(element).also { if (it) list.add(element) } | ||
} | ||
|
||
override fun addAll(elements: Collection<T>): Boolean { | ||
val toAdd = elements.filter { it !in set } // Maintain order | ||
if (toAdd.isEmpty()) return false | ||
set.addAll(toAdd) | ||
list.addAll(toAdd) | ||
return true | ||
} | ||
|
||
override fun clear() { | ||
set.clear() | ||
list.clear() | ||
} | ||
|
||
override fun iterator(): MutableIterator<T> { | ||
return object : MutableIterator<T> { | ||
private val delegate = list.iterator() | ||
private var current: T? = null | ||
|
||
override fun hasNext() = delegate.hasNext() | ||
|
||
override fun next() = delegate.next().also { | ||
current = it | ||
} | ||
|
||
override fun remove() { | ||
val p = checkNotNull(current) | ||
this@LinkedIdentityHashSet.remove(p) | ||
current = null | ||
} | ||
} | ||
} | ||
|
||
override fun remove(element: T): Boolean { | ||
return set.remove(element).also { if (it) list.remove(element) } | ||
} | ||
|
||
override fun removeAll(elements: Collection<T>): Boolean { | ||
val toRemove = set intersect elements | ||
if (toRemove.isEmpty()) return false | ||
set.removeAll(toRemove) | ||
list.removeAll(toRemove) | ||
return true | ||
} | ||
|
||
override fun retainAll(elements: Collection<T>): Boolean { | ||
return removeAll(set subtract elements) | ||
} | ||
|
||
override val size: Int | ||
get() = set.size | ||
|
||
override fun contains(element: T): Boolean { | ||
return set.contains(element) | ||
} | ||
|
||
override fun containsAll(elements: Collection<T>): Boolean { | ||
return set.containsAll(elements) | ||
} | ||
|
||
override fun isEmpty(): Boolean { | ||
return set.isEmpty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.