add compressed_payload field to both RpcRequest and RpcResponse#1403
add compressed_payload field to both RpcRequest and RpcResponse#1403xianshijing-lk wants to merge 5 commits intomainfrom
Conversation
|
| uint32 response_timeout_ms = 4; | ||
| uint32 version = 5; | ||
| // Compressed payload data. When set, this field is used instead of `payload`. | ||
| bytes compressed_payload = 6; |
There was a problem hiding this comment.
Is an alternative a possible consideration? A field like
enum Encoding {
BASE64 = 0; --> to ensure default remains the same
COMPRESSION_TYPE_1 = 1;
COMPRESSION_TYPE_2 = 2;
}
This allows an extensible format and we can have any encoding.
There was a problem hiding this comment.
GZIP will the only one available on all platforms. I actually don't see opportunity that we will support the second compression in the near term.
And when it gets to adding supported compression type, we might want to do it in the ParticipantInfo, similar to client_protocol, so that we don't need to embed the same values with every RPC, even though it might just be 2 bytes; another reason is that if some compression is not supported on some platforms, we will need to negotiate the compression before the 1st RPC msg.
What do you think ? I am OK with adding it if you feel strong about it, otherwise we will just keep it simple for now, and will do it properly when we are adding another compression.
|
A gentle ping, what do you think about the comment ? I am open to adding an enum, but would like to get confirmation we want to do it with this PR now |
Not sure who you were addressing to @xianshijing-lk . I think an enum in this PR would be great. Doing one version with |
840ee54 to
e1f730b
Compare
|
added RpcPayloadType enum there, please take another look. Thanks |
protobufs/livekit_models.proto
Outdated
| bool generated = 6; // true if the chat message has been generated by an agent from a participant's audio transcription | ||
| } | ||
|
|
||
| enum RpcPayloadType { |
There was a problem hiding this comment.
suggestion: rename to RpcPayloadEncoding and the UNCOMPRESSED part could be renamed to BASE64 if we are using BASE64. Encoding I think is a better name as it annotates the data format.
There was a problem hiding this comment.
I think there are some confusion here.
Today, we have "string payload", which can be used to send texts without compression.
It can't be as compressed_payload unless we use base64 to encode to compressed data, but base64 will add 33% overhead on the payload size.
To your question regarding BASE64, no, base64 should not be used, and we are trying to avoid it by adding a dedicated bytes compressed_payload;
RpcPayloadEncoding can be a wrong name, unless you change it to something like
{
NONE,
GZIP,
}
but I think RpcPayloadType is more telling, since it tells the type of payload, is it uncompressed or gizp compressed ?
There was a problem hiding this comment.
If we go with a bytes field, I guess UTF8 would make sense as the default.
protobufs/livekit_models.proto
Outdated
| uint32 version = 5; | ||
| // Compressed payload data. When set, this field is used instead of `payload`. | ||
| bytes compressed_payload = 6; | ||
| // Indicates the compression type used for compressed_payload. |
There was a problem hiding this comment.
Do we need a compressed_payload separate field? I was think this field would tell what encoding is used for payload field.
There was a problem hiding this comment.
Yes, it is a must unless we use base64 to encode the compress data, but that will seriously hurt the performance.
There was a problem hiding this comment.
the challenge I think is that the original field is a string and I guess we'd want bytes now.
There was a problem hiding this comment.
🤦 I missed that. Sorry.
Okay, a new field is needed.
Naming suggestion then
encoded_payload- Rename enum to
RpcPayloadEncoding
I think the naming of Encoding is more generic and can be used irrespective of whether the data is compressed or not.
There was a problem hiding this comment.
I usually don't have much strong opinion on the naming, but just think encoding != compression.
From chatgpt:
Is encoding the right term for compression?
Not really. Compression is not usually called encoding.
Encoding = changing representation so data can be transported/stored safely
Examples: UTF-8, Base64, JSON, Protobuf
Compression = reducing size by applying an algorithm
Examples: GZIP, Brotli, Zstd
So if your enum values are:
UNCOMPRESSED
GZIP
…then what you’re describing is compression, not encoding.
So what’s the best name?
Here are the most accurate options:
✅ RpcPayloadCompression
NONE
GZIP
This is the clearest and most semantically correct.
✅ RpcPayloadFormat or RpcPayloadRepresentation
If the enum is also indicating which field is populated (text vs binary).
Only makes sense if you include things like BASE64, UTF8, etc.
But in your case, payload is plain text already — so “encoding” becomes confusing.
Would RpcPayloadFormat or RpcPayloadCompression work better ?
There was a problem hiding this comment.
I think based on this and other discussions, we can probably go with the following
compressed_payloadfield- As it is always going to be GZIP, we can drop the payload type/format field and ad it later if needed.
- If we need the payload type/format and have several options, my preference would be to put it in RPC messages rather than
ParticipantInfoas each RPC message could be compressed differently based on content type, etc.
protobufs/livekit_models.proto
Outdated
| bytes compressed_payload = 4; | ||
| } | ||
| // Indicates the compression type used for compressed_payload. | ||
| RpcPayloadType payload_type = 5; |
6509cc8 to
1769510
Compare
| uint32 response_timeout_ms = 4; | ||
| uint32 version = 5; | ||
| // Compressed payload data. When set, this field is used instead of `payload`. | ||
| bytes compressed_payload = 6; |
There was a problem hiding this comment.
GZIP will the only one available on all platforms. I actually don't see opportunity that we will support the second compression in the near term.
And when it gets to adding supported compression type, we might want to do it in the ParticipantInfo, similar to client_protocol, so that we don't need to embed the same values with every RPC, even though it might just be 2 bytes; another reason is that if some compression is not supported on some platforms, we will need to negotiate the compression before the 1st RPC msg.
What do you think ? I am OK with adding it if you feel strong about it, otherwise we will just keep it simple for now, and will do it properly when we are adding another compression.
protobufs/livekit_models.proto
Outdated
| bool generated = 6; // true if the chat message has been generated by an agent from a participant's audio transcription | ||
| } | ||
|
|
||
| enum RpcPayloadType { |
There was a problem hiding this comment.
I think there are some confusion here.
Today, we have "string payload", which can be used to send texts without compression.
It can't be as compressed_payload unless we use base64 to encode to compressed data, but base64 will add 33% overhead on the payload size.
To your question regarding BASE64, no, base64 should not be used, and we are trying to avoid it by adding a dedicated bytes compressed_payload;
RpcPayloadEncoding can be a wrong name, unless you change it to something like
{
NONE,
GZIP,
}
but I think RpcPayloadType is more telling, since it tells the type of payload, is it uncompressed or gizp compressed ?
protobufs/livekit_models.proto
Outdated
| uint32 version = 5; | ||
| // Compressed payload data. When set, this field is used instead of `payload`. | ||
| bytes compressed_payload = 6; | ||
| // Indicates the compression type used for compressed_payload. |
There was a problem hiding this comment.
Yes, it is a must unless we use base64 to encode the compress data, but that will seriously hurt the performance.
protobufs/livekit_models.proto
Outdated
| uint32 version = 5; | ||
| // Compressed payload data. When set, this field is used instead of `payload`. | ||
| bytes compressed_payload = 6; | ||
| // Indicates the compression type used for compressed_payload. |
There was a problem hiding this comment.
I usually don't have much strong opinion on the naming, but just think encoding != compression.
From chatgpt:
Is encoding the right term for compression?
Not really. Compression is not usually called encoding.
Encoding = changing representation so data can be transported/stored safely
Examples: UTF-8, Base64, JSON, Protobuf
Compression = reducing size by applying an algorithm
Examples: GZIP, Brotli, Zstd
So if your enum values are:
UNCOMPRESSED
GZIP
…then what you’re describing is compression, not encoding.
So what’s the best name?
Here are the most accurate options:
✅ RpcPayloadCompression
NONE
GZIP
This is the clearest and most semantically correct.
✅ RpcPayloadFormat or RpcPayloadRepresentation
If the enum is also indicating which field is populated (text vs binary).
Only makes sense if you include things like BASE64, UTF8, etc.
But in your case, payload is plain text already — so “encoding” becomes confusing.
Would RpcPayloadFormat or RpcPayloadCompression work better ?
|
|
||
| enum RpcPayloadFormat { | ||
| RPF_UNKNOWN = 0; | ||
| RPF_GZIP = 1; |
There was a problem hiding this comment.
FYI, proto3 will have default value as 0, thus we'd better not use 0 for GZIP.
And since RpcPayloadFormat is also a top level enum in the same package, using just UNKNOWN would conflict with TrackSource.UNKNOWN.
Thus we need to add a prefix, RPF_ (abbreviation for RpcPayloadFormat) to avoid this collision.
That is the same for enum ReconnectReason {
RR_UNKNOWN = 0;
RR_SIGNAL_DISCONNECTED = 1;
RR_PUBLISHER_FAILED = 2;
RR_SUBSCRIBER_FAILED = 3;
RR_SWITCH_CANDIDATE = 4;
}
So that we don't need to use base64 to encode the string, which adds 33% of overhead