message: Mark the `SerializeSparseOp<Variant>` kernel as inexpensive.
  Since this op only performs a constant amount of work, and typically
  executes in a few microseconds, it should be profitable to execute
  this op inline, rather than scheduling it on a remote thread.
diff: @@ -44,6 +44,8 @@ class SerializeSparseOp : public OpKernel {
  explicit SerializeSparseOp(OpKernelConstruction* context)
  : OpKernel(context) {}
  + bool IsExpensive() override;
  +
  Status Initialize(Tensor* result);
  Status Serialize(const Tensor& input, T* result);
  @@ -82,6 +84,21 @@ class SerializeSparseOp : public OpKernel {
  }
  };
  +// NOTE(mrry): We specialize the IsExpensive() method differently for
  +// the string and variant cases, because (i) the string version
  +// actually performs memory copies as part of its serialization (and
  +// is hence potentially expensive), and (ii) the variant version
  +// performs O(1) shallow copies (and hence is much cheaper than
  +// dispatching to another thread would be).
  +template <>
  +bool SerializeSparseOp<string>::IsExpensive() {
  + return true;
  +}
  +template <>
  +bool SerializeSparseOp<Variant>::IsExpensive() {
  + return false;
  +}
  +
  template <>
  Status SerializeSparseOp<string>::Initialize(Tensor* result) {
  *result = Tensor(DT_STRING, TensorShape({3}));
  