Skip to content

CompilationCache size grows after compiling Lazy Schema #1856

@a-morales

Description

@a-morales

This may be related to #1815 and I have this pushed up in the lazyschema-bug-recursionspec branch

I came across this weird behavior as I was writing a test so that improvements can be measured as I made changes to Lazy. I was aiming to remove the case below in the compilation cache when updating how Lazy is represented.

// Lazy is tricky in that the thunk it contains can never be expressed
// in a "stable" way, even in a dynamic context when most accessors/injectors can be
// expressed in a serialisable fashion.
if (schema.isInstanceOf[Schema.LazySchema[_]]) { fetch(schema) }
else store.getOrElseUpdate(schema, fetch(schema)).asInstanceOf[F[A]]

I wrote a test suite where I have a recursive scheme (Tree and Cons) and I compile a SchemaVisitorHash to get an instance of Hash[Tree] and Hash[Cons] then hash some values. When I look at the size of the cache it is growing in proportion to how deeply nested the recursive scheme is, but only in the case where the schema is transformed. My assumption was that after we compile a schema the size of the cache should stay the same and not grow afterwards. after running the test here's the printed output of the results

Foo current cache, hints unchanged: sizeAfterCompilingVisitor=9, sizesAfterHashing=List(9, 9, 9, 9, 9, 9, 9)
Foo current cache, hints transformed: sizeAfterCompilingVisitor=9, sizesAfterHashing=List(9, 9, 9, 9, 9, 9, 9)
Foo updated cache, hints unchanged: sizeAfterCompilingVisitor=9, sizesAfterHashing=List(9, 9, 9, 9, 9, 9, 9)
Foo updated cache, hints transformed: sizeAfterCompilingVisitor=9, sizesAfterHashing=List(9, 9, 9, 9, 9, 9, 9)
Tree current cache, hints unchanged: sizeAfterCompilingVisitor=0, sizesAfterHashing=List(5, 7, 7, 7, 7, 7, 7)
Tree current cache, hints transformed: sizeAfterCompilingVisitor=0, sizesAfterHashing=List(5, 50, 500, 5000, 5000, 5000, 5000)
Tree updated cache, hints unchanged: sizeAfterCompilingVisitor=1, sizesAfterHashing=List(7, 11, 11, 11, 11, 11, 11)
Tree updated cache, hints transformed: sizeAfterCompilingVisitor=1, sizesAfterHashing=List(7, 88, 898, 8998, 8998, 8998, 8998)
Cons current cache, hints unchanged: sizeAfterCompilingVisitor=0, sizesAfterHashing=List(7, 7, 7, 7, 7, 7, 7)
Cons current cache, hints transformed: sizeAfterCompilingVisitor=0, sizesAfterHashing=List(8, 35, 305, 3005, 3005, 3005, 3005)
Cons updated cache, hints unchanged: sizeAfterCompilingVisitor=1, sizesAfterHashing=List(10, 10, 10, 10, 10, 10, 10)
Cons updated cache, hints transformed: sizeAfterCompilingVisitor=1, sizesAfterHashing=List(12, 57, 507, 5007, 5007, 5007, 5007)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions