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.
Commit
f5b559af94346f86f04519024bfd8fd2fd3db52b339d7b3c8ad06005241c9dd6
Parent
22e7b78dce5123e…
2 files changed
+5
-5
+62
+5
-5
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -567,10 +567,15 @@ | ||
| 567 | 567 | cgi_combine_header_and_body(); |
| 568 | 568 | blob_compress(&cgiContent[0], &cgiContent[0]); |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | if( iReplyStatus!=206 ){ |
| 572 | +#ifdef HAVE_BROTLIENCODERCOMPRESS | |
| 573 | + if( 0 && is_compressible(COMPRESSIBLE_BROTLI) ){ | |
| 574 | + /* TODO */ | |
| 575 | + }else | |
| 576 | +#endif | |
| 572 | 577 | if( is_compressible(COMPRESSIBLE_ZLIB) ){ |
| 573 | 578 | int i; |
| 574 | 579 | gzip_begin(0); |
| 575 | 580 | for( i=0; i<2; i++ ){ |
| 576 | 581 | int size = blob_size(&cgiContent[i]); |
| @@ -579,15 +584,10 @@ | ||
| 579 | 584 | } |
| 580 | 585 | gzip_finish(&cgiContent[0]); |
| 581 | 586 | blob_appendf(&hdr, "Content-Encoding: gzip\r\n"); |
| 582 | 587 | blob_appendf(&hdr, "Vary: Accept-Encoding\r\n"); |
| 583 | 588 | } |
| 584 | -#ifdef HAVE_BROTLIENCODERCOMPRESS | |
| 585 | - else if( is_compressible(COMPRESSIBLE_BROTLI) ){ | |
| 586 | - /* TODO */ | |
| 587 | - } | |
| 588 | -#endif | |
| 589 | 589 | } |
| 590 | 590 | total_size = blob_size(&cgiContent[0]) + blob_size(&cgiContent[1]); |
| 591 | 591 | if( iReplyStatus==206 ){ |
| 592 | 592 | blob_appendf(&hdr, "Content-Range: bytes %d-%d/%d\r\n", |
| 593 | 593 | rangeStart, rangeEnd-1, total_size); |
| 594 | 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 | 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 @@ | ||
| 136 | 136 | gzip_finish(&b); |
| 137 | 137 | blob_write_to_file(&b, zOut); |
| 138 | 138 | blob_reset(&b); |
| 139 | 139 | fossil_free(zOut); |
| 140 | 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 */ | |
| 141 | 203 |
| --- 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 |