atlasdb icon indicating copy to clipboard operation
atlasdb copied to clipboard

[Generated Code] Fresh Persister Object Created On Every Hydration

Open jeremyk-91 opened this issue 6 years ago • 1 comments
trafficstars

Currently, the implementation of the bytes hydrator for a user-specified persister is to create a new instance of the persister on each hydration, and then decompress the values. This leads to unnecessary object allocations when the persister is not stateful, and has been flagged as possibly causing issues for internal shopping product.

For example, for schema code:

        schema.addTableDefinition("table", new TableDefinition() {{
            rowName();
            rowComponent("row", ValueType.STRING);
            columns();
            column("column", "c", JPersister.class);
        }});

We get in the generated code:

        public static final Hydrator<Column> BYTES_HYDRATOR = new Hydrator<Column>() {
            @Override
            public Column hydrateFromBytes(byte[] bytes) {
                bytes = CompressionUtils.decompress(bytes, Compression.NONE);
                return of(new com.palantir.atlasdb.todo.JPersister().hydrateFromBytes(com.palantir.atlasdb.compress.CompressionUtils.decompress(bytes, com.palantir.atlasdb.table.description.ColumnValueDescription.Compression.NONE)));
            }
        };

Note that in general this needs to be configurable and default to off to avoid issues with users whose persisters are stateful (and thus creating a new one on every hydration is required).

jeremyk-91 avatar Jul 12 '19 12:07 jeremyk-91

stateful persisters???

felixdesouza avatar Jul 12 '19 13:07 felixdesouza