-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer interning combos/components/bands over basic features.
This optimization saves memory up to 90% for 5k capabilities or 60% for 1k capabilities.
- Loading branch information
1 parent
a3cec4c
commit b55c0eb
Showing
3 changed files
with
49 additions
and
42 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
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
60 changes: 33 additions & 27 deletions
60
src/main/java/it/smartphonecombo/uecapabilityparser/util/Optimization.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 |
---|---|---|
@@ -1,42 +1,48 @@ | ||
package it.smartphonecombo.uecapabilityparser.util | ||
|
||
import it.smartphonecombo.uecapabilityparser.extension.trimToSize | ||
import it.smartphonecombo.uecapabilityparser.extension.typedList | ||
import it.smartphonecombo.uecapabilityparser.model.Capabilities | ||
import it.smartphonecombo.uecapabilityparser.model.band.IBandDetails | ||
import it.smartphonecombo.uecapabilityparser.model.combo.ComboEnDc | ||
import it.smartphonecombo.uecapabilityparser.model.combo.ComboLte | ||
import it.smartphonecombo.uecapabilityparser.model.combo.ComboNr | ||
import it.smartphonecombo.uecapabilityparser.model.combo.ComboNrDc | ||
import it.smartphonecombo.uecapabilityparser.model.combo.ICombo | ||
import it.smartphonecombo.uecapabilityparser.model.component.ComponentNr | ||
import it.smartphonecombo.uecapabilityparser.model.component.IComponent | ||
|
||
internal fun Capabilities.optimize() { | ||
lteBands.forEach { it.optimize() } | ||
nrBands.forEach { it.optimize() } | ||
lteCombos.forEach { it.optimize() } | ||
nrCombos.forEach { it.optimize() } | ||
nrDcCombos.forEach { it.optimize() } | ||
enDcCombos.forEach { it.optimize() } | ||
} | ||
// bands | ||
lteBands = lteBands.map(IBandDetails::intern).typedList() | ||
nrBands = nrBands.map(IBandDetails::intern).typedList() | ||
|
||
internal fun IBandDetails.optimize() { | ||
mimoDL = mimoDL.intern() | ||
mimoUL = mimoUL.intern() | ||
modDL = modDL.intern() | ||
modUL = modUL.intern() | ||
// combos | ||
lteCombos = lteCombos.map(ICombo::optimizeAndIntern).typedList() | ||
nrCombos = nrCombos.map(ICombo::optimizeAndIntern).typedList() | ||
nrDcCombos = nrDcCombos.map(ICombo::optimizeAndIntern).typedList() | ||
enDcCombos = enDcCombos.map(ICombo::optimizeAndIntern).typedList() | ||
} | ||
|
||
internal fun ICombo.optimize() { | ||
masterComponents.trimToSize() | ||
masterComponents.forEach { it.optimize() } | ||
secondaryComponents.trimToSize() | ||
secondaryComponents.forEach { it.optimize() } | ||
private fun ICombo.optimizeAndIntern(): ICombo { | ||
val res = if (alreadyInterned()) this else optimized() | ||
return res.intern() | ||
} | ||
|
||
internal fun IComponent.optimize() { | ||
mimoDL = mimoDL.intern() | ||
mimoUL = mimoUL.intern() | ||
modDL = modDL.intern() | ||
modUL = modUL.intern() | ||
if (this is ComponentNr) { | ||
maxBandwidthDl = maxBandwidthDl.intern() | ||
maxBandwidthUl = maxBandwidthUl.intern() | ||
private fun ICombo.optimized(): ICombo { | ||
val masterComponentsOpt = masterComponents.map(IComponent::intern) | ||
val secondaryComponentsOpt = secondaryComponents.map(IComponent::intern) | ||
|
||
return when (this) { | ||
is ComboLte -> copy(masterComponents = masterComponentsOpt.typedList()) | ||
is ComboNr -> copy(masterComponents = masterComponentsOpt.typedList()) | ||
is ComboNrDc -> | ||
copy( | ||
masterComponents = masterComponentsOpt.typedList(), | ||
secondaryComponents = secondaryComponentsOpt.typedList(), | ||
) | ||
is ComboEnDc -> | ||
copy( | ||
masterComponents = masterComponentsOpt.typedList(), | ||
secondaryComponents = secondaryComponentsOpt.typedList(), | ||
) | ||
} | ||
} |