@@ -94,8 +94,12 @@ pub trait WebsocketFormat: Sized {
9494 type QueryUpdate : SpacetimeType + for < ' de > Deserialize < ' de > + Serialize + Debug + Clone + Send ;
9595
9696 /// Convert a `QueryUpdate` into `Self::QueryUpdate`.
97- /// This allows some formats to e.g., compress the update.
98- fn into_query_update ( qu : QueryUpdate < Self > , compression : Compression ) -> Self :: QueryUpdate ;
97+ ///
98+ /// We don't compress individual table updates anymore for any format.
99+ /// Previously we did, but the benefits, if any, were unclear.
100+ /// Note that each message is still compressed before being sent to clients,
101+ /// but we no longer have to hold a tx lock when doing so.
102+ fn into_query_update ( qu : QueryUpdate < Self > ) -> Self :: QueryUpdate ;
99103}
100104
101105/// Messages sent from the client to the server.
@@ -770,7 +774,7 @@ impl WebsocketFormat for JsonFormat {
770774
771775 type QueryUpdate = QueryUpdate < Self > ;
772776
773- fn into_query_update ( qu : QueryUpdate < Self > , _ : Compression ) -> Self :: QueryUpdate {
777+ fn into_query_update ( qu : QueryUpdate < Self > ) -> Self :: QueryUpdate {
774778 qu
775779 }
776780}
@@ -813,24 +817,8 @@ impl WebsocketFormat for BsatnFormat {
813817
814818 type QueryUpdate = CompressableQueryUpdate < Self > ;
815819
816- fn into_query_update ( qu : QueryUpdate < Self > , compression : Compression ) -> Self :: QueryUpdate {
817- let qu_len_would_have_been = bsatn:: to_len ( & qu) . unwrap ( ) ;
818-
819- match decide_compression ( qu_len_would_have_been, compression) {
820- Compression :: None => CompressableQueryUpdate :: Uncompressed ( qu) ,
821- Compression :: Brotli => {
822- let bytes = bsatn:: to_vec ( & qu) . unwrap ( ) ;
823- let mut out = Vec :: new ( ) ;
824- brotli_compress ( & bytes, & mut out) ;
825- CompressableQueryUpdate :: Brotli ( out. into ( ) )
826- }
827- Compression :: Gzip => {
828- let bytes = bsatn:: to_vec ( & qu) . unwrap ( ) ;
829- let mut out = Vec :: new ( ) ;
830- gzip_compress ( & bytes, & mut out) ;
831- CompressableQueryUpdate :: Gzip ( out. into ( ) )
832- }
833- }
820+ fn into_query_update ( qu : QueryUpdate < Self > ) -> Self :: QueryUpdate {
821+ CompressableQueryUpdate :: Uncompressed ( qu)
834822 }
835823}
836824
@@ -846,13 +834,9 @@ pub enum Compression {
846834 Gzip ,
847835}
848836
849- pub fn decide_compression ( len : usize , compression : Compression ) -> Compression {
850- /// The threshold beyond which we start to compress messages.
851- /// 1KiB was chosen without measurement.
852- /// TODO(perf): measure!
853- const COMPRESS_THRESHOLD : usize = 1024 ;
854-
855- if len > COMPRESS_THRESHOLD {
837+ /// Based on the `len` of a message and a `threshold`, potentially clamp `compression` to `None`.
838+ pub fn decide_compression ( len : usize , threshold : usize , compression : Compression ) -> Compression {
839+ if len > threshold {
856840 compression
857841 } else {
858842 Compression :: None
0 commit comments