@@ -126,7 +126,7 @@ class VariablesSerializer(
126126 private val serializationLimit : Int = 10000 ,
127127 private val cellCountRemovalThreshold : Int = 5 ,
128128 // let's make this flag customizable from Jupyter config menu
129- val shouldRemoveOldVariablesFromCache : Boolean = true
129+ val shouldRemoveOldDescriptors : Boolean = false
130130) : ClearableSerializer<Int> {
131131
132132 fun MutableMap <String , SerializedVariablesState ?>.addDescriptor (value : Any? , name : String = value.toString()) {
@@ -330,24 +330,8 @@ class VariablesSerializer(
330330
331331 private val isSerializationActive: Boolean = System .getProperty(serializationSystemProperty)?.toBooleanStrictOrNull() ? : true
332332
333- /* *
334- * Cache for not recomputing unchanged variables
335- */
336- private val serializedVariablesCache: MutableMap <String , SerializedVariablesState > = mutableMapOf ()
337-
338- private val removedFromSightVariables: MutableSet <String > = mutableSetOf ()
339-
340333 private suspend fun clearOldData (currentCellId : Int , cellVariables : Map <Int , Set <String >>) {
341- fun removeFromCache (cellId : Int ) {
342- val oldDeclarations = cellVariables[cellId]
343- oldDeclarations?.let { oldSet ->
344- oldSet.forEach { varName ->
345- serializedVariablesCache.remove(varName)
346- removedFromSightVariables.add(varName)
347- }
348- }
349- }
350-
334+ if (! shouldRemoveOldDescriptors) return
351335 val setToRemove = mutableSetOf<Int >()
352336 computedDescriptorsPerCell.forEach { (cellNumber, _) ->
353337 if (abs(currentCellId - cellNumber) >= cellCountRemovalThreshold) {
@@ -357,9 +341,6 @@ class VariablesSerializer(
357341 log.debug(" Removing old info about cells: $setToRemove " )
358342 setToRemove.forEach {
359343 clearStateInfo(it)
360- if (shouldRemoveOldVariablesFromCache) {
361- removeFromCache(it)
362- }
363344 }
364345 }
365346
@@ -369,7 +350,6 @@ class VariablesSerializer(
369350
370351 override suspend fun clearStateInfo (currentState : Int ) {
371352 computedDescriptorsPerCell.remove(currentState)
372- // seenObjectsPerVariable.remove(currentState)
373353 }
374354
375355 suspend fun tryValidateCache (currentCellId : Int , cellVariables : Map <Int , Set <String >>) {
@@ -378,42 +358,17 @@ class VariablesSerializer(
378358 }
379359
380360 fun serializeVariables (cellId : Int , variablesState : Map <String , VariableState >, oldDeclarations : Map <String , Int >, variablesCells : Map <String , Int >, unchangedVariables : Set <String >): Map <String , SerializedVariablesState > {
381- fun removeNonExistingEntries () {
382- val toRemoveSet = mutableSetOf<String >()
383- serializedVariablesCache.forEach { (name, _) ->
384- // seems like this never gonna happen
385- if (! variablesState.containsKey(name)) {
386- toRemoveSet.add(name)
387- }
388- }
389- toRemoveSet.forEach { serializedVariablesCache.remove(it) }
390- }
391-
392361 if (! isSerializationActive) return emptyMap()
393362
394363 if (variablesState.isEmpty()) {
395364 return emptyMap()
396365 }
397366 currentSerializeCount = 0
398- val neededEntries = variablesState.filterKeys {
399- val wasRedeclared = ! unchangedVariables.contains(it)
400- if (wasRedeclared) {
401- removedFromSightVariables.remove(it)
402- }
403- // TODO: might consider self-recursive elements always to recompute since it's non comparable via strings
404- if (serializedVariablesCache.isEmpty()) {
405- true
406- } else {
407- (! unchangedVariables.contains(it) || serializedVariablesCache[it]?.value != variablesState[it]?.stringValue) &&
408- ! removedFromSightVariables.contains(it)
409- }
410- }
411367 log.debug(" Variables state as is: $variablesState " )
412- log.debug(" Serializing variables after filter: $neededEntries " )
413- log.debug(" Unchanged variables: ${unchangedVariables - neededEntries.keys} " )
368+ log.debug(" Unchanged variables: ${unchangedVariables - variablesState.keys} " )
414369
415370 // remove previous data
416- val serializedData = neededEntries .mapValues {
371+ val serializedData = variablesState .mapValues {
417372 val actualCell = variablesCells[it.key] ? : cellId
418373 if (oldDeclarations.containsKey(it.key)) {
419374 val oldCell = oldDeclarations[it.key]!!
@@ -422,12 +377,9 @@ class VariablesSerializer(
422377 }
423378 serializeVariableState(actualCell, it.key, it.value)
424379 }
380+ log.debug(serializedData.entries.toString())
425381
426- serializedVariablesCache.putAll(serializedData)
427- removeNonExistingEntries()
428- log.debug(serializedVariablesCache.entries.toString())
429-
430- return serializedVariablesCache
382+ return serializedData
431383 }
432384
433385 fun doIncrementalSerialization (
0 commit comments