diff --git a/tensorflow/core/kernels/example_parsing_ops.cc b/tensorflow/core/kernels/example_parsing_ops.cc index 528b3c6bf07553e9aeaddb4c00ef3b0e19a8b516..708b52a5174fdcf1ee084add8de23f8ef2f0c07f 100644 --- a/tensorflow/core/kernels/example_parsing_ops.cc +++ b/tensorflow/core/kernels/example_parsing_ops.cc @@ -591,7 +591,22 @@ class ParseSingleSequenceExampleOp : public OpKernel { OP_REQUIRES_OK(ctx, ctx->output_list("feature_list_dense_values", &feature_list_dense_values)); +#ifdef TENSORFLOW_LITE_PROTOS SequenceExample ex; +#else + // Allocate the SequenceExample on an arena. Provides better memory locality + // and greatly speeds up destruction. + protobuf::ArenaOptions options; + // We have some hint of what the final proto size will be based on the size + // of the serialized bytes- use this to set a custom allocation strategy. + // Note that the default allocation strategy is quite conservative (min + // block size of 256 bytes, and a max of 8 kilobytes). + const size_t block_size = serialized_t().size() * 1.1; + options.start_block_size = std::max(options.start_block_size, block_size); + options.max_block_size = std::max(options.max_block_size, block_size); + protobuf::Arena arena(options); + auto& ex = *protobuf::Arena::CreateMessage(&arena); +#endif OP_REQUIRES( ctx, ParseProtoUnlimited(&ex, serialized_t()), errors::InvalidArgument("Could not parse example input, value: '",