google / google/built_value.dart

High Memory Usage of built_value_generator to due memoization + keeping all SerializerSourceClass objects in memory

Open
#1,288 6 comments 4 reactions 1 assignee Claimed by @davidmorgan View on GitHub
p2 / feature request
Dominant language
Dart
Stars
886
Forks
195
Avg merge
1d 11h
Merged PRs (30d)
4

Description

Hi, it's me again with issues that pop up due to ferry using built_value for serialization of generated graphql code, which can get quite big ;)

`built_value_generator` keeps a list of `SerializerSourceClass` for a `SerializerSourceLibrary`.

So all the `SerializerSourceClass` objects are kept in memory, and they use memoization to keep e.g. their `parsedLibrary` and `SerializerSourceField` `fields` cached.

This leads to very high memory usage in cases where there are a very high number of serializers.

For reference: https://github.com/gql-dart/ferry/issues/558#issuecomment-1854197907

This can probably be fixed with little changes to the code, e.g. be copying the currently active `SerializerSourceClass` into a new object which can is not held in a list after the code generation is done
(e.g. `sourceClasses.map((clazz) => clazz.rebuild((b) => b))`, so the objects with memoized fields are eligible for garbage collection after work is finished for that class.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.