@@ -126,7 +126,7 @@ class VariablesSerializer(
126
126
private val serializationLimit : Int = 10000 ,
127
127
private val cellCountRemovalThreshold : Int = 5 ,
128
128
// let's make this flag customizable from Jupyter config menu
129
- val shouldRemoveOldVariablesFromCache : Boolean = true
129
+ val shouldRemoveOldDescriptors : Boolean = false
130
130
) : ClearableSerializer<Int> {
131
131
132
132
fun MutableMap <String , SerializedVariablesState ?>.addDescriptor (value : Any? , name : String = value.toString()) {
@@ -330,24 +330,8 @@ class VariablesSerializer(
330
330
331
331
private val isSerializationActive: Boolean = System .getProperty(serializationSystemProperty)?.toBooleanStrictOrNull() ? : true
332
332
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
-
340
333
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
351
335
val setToRemove = mutableSetOf<Int >()
352
336
computedDescriptorsPerCell.forEach { (cellNumber, _) ->
353
337
if (abs(currentCellId - cellNumber) >= cellCountRemovalThreshold) {
@@ -357,9 +341,6 @@ class VariablesSerializer(
357
341
log.debug(" Removing old info about cells: $setToRemove " )
358
342
setToRemove.forEach {
359
343
clearStateInfo(it)
360
- if (shouldRemoveOldVariablesFromCache) {
361
- removeFromCache(it)
362
- }
363
344
}
364
345
}
365
346
@@ -369,7 +350,6 @@ class VariablesSerializer(
369
350
370
351
override suspend fun clearStateInfo (currentState : Int ) {
371
352
computedDescriptorsPerCell.remove(currentState)
372
- // seenObjectsPerVariable.remove(currentState)
373
353
}
374
354
375
355
suspend fun tryValidateCache (currentCellId : Int , cellVariables : Map <Int , Set <String >>) {
@@ -378,42 +358,17 @@ class VariablesSerializer(
378
358
}
379
359
380
360
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
-
392
361
if (! isSerializationActive) return emptyMap()
393
362
394
363
if (variablesState.isEmpty()) {
395
364
return emptyMap()
396
365
}
397
366
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
- }
411
367
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} " )
414
369
415
370
// remove previous data
416
- val serializedData = neededEntries .mapValues {
371
+ val serializedData = variablesState .mapValues {
417
372
val actualCell = variablesCells[it.key] ? : cellId
418
373
if (oldDeclarations.containsKey(it.key)) {
419
374
val oldCell = oldDeclarations[it.key]!!
@@ -422,12 +377,9 @@ class VariablesSerializer(
422
377
}
423
378
serializeVariableState(actualCell, it.key, it.value)
424
379
}
380
+ log.debug(serializedData.entries.toString())
425
381
426
- serializedVariablesCache.putAll(serializedData)
427
- removeNonExistingEntries()
428
- log.debug(serializedVariablesCache.entries.toString())
429
-
430
- return serializedVariablesCache
382
+ return serializedData
431
383
}
432
384
433
385
fun doIncrementalSerialization (
0 commit comments