Fossil SCM

Add test-brotli command to get some basic compression measurements. Closing this branch, as brotli is simply too slow for what we want to do.

stephan 2025-04-01 12:16 brotli-compress
Commit f5b559af94346f86f04519024bfd8fd2fd3db52b339d7b3c8ad06005241c9dd6
2 files changed +5 -5 +62
+5 -5
--- src/cgi.c
+++ src/cgi.c
@@ -567,10 +567,15 @@
567567
cgi_combine_header_and_body();
568568
blob_compress(&cgiContent[0], &cgiContent[0]);
569569
}
570570
571571
if( iReplyStatus!=206 ){
572
+#ifdef HAVE_BROTLIENCODERCOMPRESS
573
+ if( 0 && is_compressible(COMPRESSIBLE_BROTLI) ){
574
+ /* TODO */
575
+ }else
576
+#endif
572577
if( is_compressible(COMPRESSIBLE_ZLIB) ){
573578
int i;
574579
gzip_begin(0);
575580
for( i=0; i<2; i++ ){
576581
int size = blob_size(&cgiContent[i]);
@@ -579,15 +584,10 @@
579584
}
580585
gzip_finish(&cgiContent[0]);
581586
blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
582587
blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
583588
}
584
-#ifdef HAVE_BROTLIENCODERCOMPRESS
585
- else if( is_compressible(COMPRESSIBLE_BROTLI) ){
586
- /* TODO */
587
- }
588
-#endif
589589
}
590590
total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]);
591591
if( iReplyStatus==206 ){
592592
blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n",
593593
rangeStart, rangeEnd-1, total_size);
594594
--- src/cgi.c
+++ src/cgi.c
@@ -567,10 +567,15 @@
567 cgi_combine_header_and_body();
568 blob_compress(&cgiContent[0], &cgiContent[0]);
569 }
570
571 if( iReplyStatus!=206 ){
 
 
 
 
 
572 if( is_compressible(COMPRESSIBLE_ZLIB) ){
573 int i;
574 gzip_begin(0);
575 for( i=0; i<2; i++ ){
576 int size = blob_size(&cgiContent[i]);
@@ -579,15 +584,10 @@
579 }
580 gzip_finish(&cgiContent[0]);
581 blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
582 blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
583 }
584 #ifdef HAVE_BROTLIENCODERCOMPRESS
585 else if( is_compressible(COMPRESSIBLE_BROTLI) ){
586 /* TODO */
587 }
588 #endif
589 }
590 total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]);
591 if( iReplyStatus==206 ){
592 blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n",
593 rangeStart, rangeEnd-1, total_size);
594
--- src/cgi.c
+++ src/cgi.c
@@ -567,10 +567,15 @@
567 cgi_combine_header_and_body();
568 blob_compress(&cgiContent[0], &cgiContent[0]);
569 }
570
571 if( iReplyStatus!=206 ){
572 #ifdef HAVE_BROTLIENCODERCOMPRESS
573 if( 0 && is_compressible(COMPRESSIBLE_BROTLI) ){
574 /* TODO */
575 }else
576 #endif
577 if( is_compressible(COMPRESSIBLE_ZLIB) ){
578 int i;
579 gzip_begin(0);
580 for( i=0; i<2; i++ ){
581 int size = blob_size(&cgiContent[i]);
@@ -579,15 +584,10 @@
584 }
585 gzip_finish(&cgiContent[0]);
586 blob_appendf(&hdr, "Content-Encoding: gzip\r\n");
587 blob_appendf(&hdr, "Vary: Accept-Encoding\r\n");
588 }
 
 
 
 
 
589 }
590 total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]);
591 if( iReplyStatus==206 ){
592 blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n",
593 rangeStart, rangeEnd-1, total_size);
594
+62
--- src/gzip.c
+++ src/gzip.c
@@ -136,5 +136,67 @@
136136
gzip_finish(&b);
137137
blob_write_to_file(&b, zOut);
138138
blob_reset(&b);
139139
fossil_free(zOut);
140140
}
141
+
142
+#ifdef HAVE_BROTLIENCODERCOMPRESS
143
+#include <brotli/encode.h>
144
+
145
+void brotli_compress(Blob *pIn, Blob *pOut){
146
+ assert( pIn!=pOut );
147
+}
148
+
149
+/*
150
+** COMMAND: test-brotli
151
+**
152
+** Usage: %fossil test-brotli ?-quality N? ?-text? FILENAME
153
+**
154
+** Compress a file using brotli.
155
+**
156
+*/
157
+void test_brotli_compress(void){
158
+ Blob b = empty_blob;
159
+ Blob enc = empty_blob;
160
+ char *zOut;
161
+ size_t nMaxEnc;
162
+ int timerId;
163
+ sqlite3_uint64 nUsec;
164
+ int rc;
165
+ const char * zQuality = find_option("quality","q",1);
166
+ const int bTextMode = find_option("text","t",0)!=0;
167
+ const int iQuality = strtol(zQuality ? zQuality : "1", NULL, 10);
168
+ if( g.argc!=3 ) usage("FILENAME");
169
+ sqlite3_open(":memory:", &g.db);
170
+ blob_read_from_file(&b, g.argv[2], ExtFILE);
171
+ zOut = mprintf("%s.br", g.argv[2]);
172
+
173
+ nMaxEnc = BrotliEncoderMaxCompressedSize((unsigned)blob_size(&b));
174
+ fossil_print("Input size: %u bytes. ", (unsigned)blob_size(&b));
175
+ blob_reserve(&enc, (unsigned)nMaxEnc);
176
+ timerId = fossil_timer_start();
177
+ rc = BrotliEncoderCompress(
178
+ iQuality,
179
+ BROTLI_DEFAULT_WINDOW,
180
+ bTextMode ? BROTLI_MODE_TEXT : BROTLI_DEFAULT_MODE,
181
+ (size_t)blob_size(&b),
182
+ (const unsigned char*)blob_str(&b),
183
+ &nMaxEnc,
184
+ (unsigned char *)blob_str(&enc)
185
+ );
186
+ nUsec = fossil_timer_stop(timerId);
187
+ if( 0==rc ){
188
+ fossil_fatal("Compression failed for unknown reason");
189
+ }
190
+ fossil_print("BrotliEncoderCompress(q=%d, mode=%s) size=%u in %.2fms\n",
191
+ iQuality, bTextMode ? "text" : "default",
192
+ (unsigned)nMaxEnc,
193
+ (double)(nUsec / 1000.0));
194
+ if(0){
195
+ fossil_print("TODO: actually compress\n");
196
+ blob_write_to_file(&b, zOut);
197
+ }
198
+ blob_reset(&b);
199
+ blob_reset(&enc);
200
+ fossil_free(zOut);
201
+}
202
+#endif /* HAVE_BROTLIENCODERCOMPRESS */
141203
--- src/gzip.c
+++ src/gzip.c
@@ -136,5 +136,67 @@
136 gzip_finish(&b);
137 blob_write_to_file(&b, zOut);
138 blob_reset(&b);
139 fossil_free(zOut);
140 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
--- src/gzip.c
+++ src/gzip.c
@@ -136,5 +136,67 @@
136 gzip_finish(&b);
137 blob_write_to_file(&b, zOut);
138 blob_reset(&b);
139 fossil_free(zOut);
140 }
141
142 #ifdef HAVE_BROTLIENCODERCOMPRESS
143 #include <brotli/encode.h>
144
145 void brotli_compress(Blob *pIn, Blob *pOut){
146 assert( pIn!=pOut );
147 }
148
149 /*
150 ** COMMAND: test-brotli
151 **
152 ** Usage: %fossil test-brotli ?-quality N? ?-text? FILENAME
153 **
154 ** Compress a file using brotli.
155 **
156 */
157 void test_brotli_compress(void){
158 Blob b = empty_blob;
159 Blob enc = empty_blob;
160 char *zOut;
161 size_t nMaxEnc;
162 int timerId;
163 sqlite3_uint64 nUsec;
164 int rc;
165 const char * zQuality = find_option("quality","q",1);
166 const int bTextMode = find_option("text","t",0)!=0;
167 const int iQuality = strtol(zQuality ? zQuality : "1", NULL, 10);
168 if( g.argc!=3 ) usage("FILENAME");
169 sqlite3_open(":memory:", &g.db);
170 blob_read_from_file(&b, g.argv[2], ExtFILE);
171 zOut = mprintf("%s.br", g.argv[2]);
172
173 nMaxEnc = BrotliEncoderMaxCompressedSize((unsigned)blob_size(&b));
174 fossil_print("Input size: %u bytes. ", (unsigned)blob_size(&b));
175 blob_reserve(&enc, (unsigned)nMaxEnc);
176 timerId = fossil_timer_start();
177 rc = BrotliEncoderCompress(
178 iQuality,
179 BROTLI_DEFAULT_WINDOW,
180 bTextMode ? BROTLI_MODE_TEXT : BROTLI_DEFAULT_MODE,
181 (size_t)blob_size(&b),
182 (const unsigned char*)blob_str(&b),
183 &nMaxEnc,
184 (unsigned char *)blob_str(&enc)
185 );
186 nUsec = fossil_timer_stop(timerId);
187 if( 0==rc ){
188 fossil_fatal("Compression failed for unknown reason");
189 }
190 fossil_print("BrotliEncoderCompress(q=%d, mode=%s) size=%u in %.2fms\n",
191 iQuality, bTextMode ? "text" : "default",
192 (unsigned)nMaxEnc,
193 (double)(nUsec / 1000.0));
194 if(0){
195 fossil_print("TODO: actually compress\n");
196 blob_write_to_file(&b, zOut);
197 }
198 blob_reset(&b);
199 blob_reset(&enc);
200 fossil_free(zOut);
201 }
202 #endif /* HAVE_BROTLIENCODERCOMPRESS */
203

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button