diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 196106f5..56ef87ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,6 +49,7 @@ jobs: env: VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }} VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.triplet }} + VCPKG_BUILD_TYPE: release with: runVcpkgInstall: true runVcpkgFormatString: '["install", "--clean-after-build"]' @@ -83,9 +84,6 @@ jobs: - run: opam exec -- opam install . --deps-only --with-test - run: opam exec -- dune build --verbose - - name: Give binary system-specific name - run: cp "_build/default/bin/ODiffBin.exe" "odiff-${{ matrix.artifact }}.exe" - - run: opam exec -- dune exec ODiffBin -- --version - run: opam exec -- dune runtest @@ -106,11 +104,21 @@ jobs: run: npm ci - name: e2e test run: npm test + + - name: Build release binary + # this is needed because now ocaml's internal cygwin will be used on windows + # which breaks normal line endings + env: + SHELLOPTS: igncr + run: | + opam exec -- dune clean && \ + opam exec -- dune build --release && \ + cp "_build/default/bin/ODiffBin.exe" "odiff-${{ matrix.artifact }}.exe" - if: always() uses: actions/upload-artifact@v4 with: - if-no-files-found: ignore + if-no-files-found: error name: odiff-${{ matrix.artifact }}.exe path: odiff-${{ matrix.artifact }}.exe retention-days: 14 diff --git a/bin/Main.ml b/bin/Main.ml index 2fc64e26..4894b509 100644 --- a/bin/Main.ml +++ b/bin/Main.ml @@ -20,19 +20,22 @@ let main img1Path img2Path diffPath threshold outputDiffMask failOnLayoutChange diffColorHex toEmitStdoutParsableString antialiasing ignoreRegions diffLines disableGcOptimizations = (* - We do not need to actually maintain memory size of the allocated RAM by odiff, so we are - increasing the minor memory size to avoid most of the possible deallocations. For sure it is - not possible be sure that it won't be run in OCaml because we allocate the Stack and Queue + Increase amount of allowed overhead to reduce amount of GC work and cycles. + we target 1-2 minor collections per run which is the best tradeoff between + amount of memory allocated and time spend on GC. - By default set the minor heap size to 256mb on 64bit machine + For sure it depends on the image size and architecture. Primary target x86_64 *) if not disableGcOptimizations then Gc.set { (Gc.get ()) with - Gc.minor_heap_size = 64_000_000; - Gc.stack_limit = 2_048_000; - Gc.window_size = 25; + (* 128 MB *) + major_heap_increment = 128 * 1024 * 1024; + (* Reasonable high value to reduce major GC frequency *) + space_overhead = 500; + (* Disable compaction *) + max_overhead = 1_000_000; }; let module IO1 = (val getIOModule img1Path) in @@ -64,5 +67,5 @@ let main img1Path img2Path diffPath threshold outputDiffMask failOnLayoutChange | Some output when outputDiffMask -> IO1.freeImage output | _ -> ()); - (*Gc.print_stat stdout;*) + (* Gc.print_stat stdout; *) exit exitCode diff --git a/dune-project b/dune-project index 880abdf0..1ac0d9dd 100644 --- a/dune-project +++ b/dune-project @@ -12,6 +12,7 @@ (generate_opam_files true) +(version 0.3.1-rc.3) (source (github dmtrKovalenko/odiff)) (license MIT) (authors "Dmitriy Kovalenko") @@ -19,7 +20,6 @@ (package (name odiff) - (version 0.3.1-rc.3) (synopsis "CLI for comparing images pixel-by-pixel") (depends odiff-core diff --git a/images/water-diff.png b/images/water-diff.png index 998be444..3fd60200 100644 Binary files a/images/water-diff.png and b/images/water-diff.png differ diff --git a/io/jpg/dune b/io/jpg/dune index 5517a6f3..0cac8cb1 100644 --- a/io/jpg/dune +++ b/io/jpg/dune @@ -8,7 +8,7 @@ (language c) (names ReadJpg) (flags - (:include jpg_c_flags.sexp))) + (:include jpg_c_flags.sexp) -O3)) (c_library_flags (:include jpg_c_library_flags.sexp)) (libraries odiff-core WritePng)) diff --git a/io/png/ReadPng.c b/io/png/ReadPng.c index fb9f6713..6526232c 100644 --- a/io/png/ReadPng.c +++ b/io/png/ReadPng.c @@ -24,7 +24,7 @@ CAMLprim value read_png_file(value file) { ctx = spng_ctx_new(0); if (ctx == NULL) { - fclose(png); + fclose(png); caml_failwith("spng_ctx_new() failed"); } @@ -56,7 +56,8 @@ CAMLprim value read_png_file(value file) { caml_failwith(spng_strerror(result)); }; - ba = caml_ba_alloc(CAML_BA_UINT8 | CAML_BA_C_LAYOUT | CAML_BA_MANAGED, 1, NULL, &out_size); + ba = caml_ba_alloc(CAML_BA_UINT8 | CAML_BA_C_LAYOUT | CAML_BA_MANAGED, 1, + NULL, &out_size); unsigned char *out = (unsigned char *)Caml_ba_data_val(ba); result = diff --git a/io/png/dune b/io/png/dune index a1746aad..39b282a1 100644 --- a/io/png/dune +++ b/io/png/dune @@ -8,7 +8,7 @@ (language c) (names ReadPng) (flags - (:include png_c_flags.sexp))) + (:include png_c_flags.sexp) -O3)) (c_library_flags (:include png_c_library_flags.sexp)) (libraries odiff-core WritePng)) diff --git a/io/png_write/dune b/io/png_write/dune index cff8c632..b967aac3 100644 --- a/io/png_write/dune +++ b/io/png_write/dune @@ -8,7 +8,7 @@ (language c) (names WritePng) (flags - (:include png_write_c_flags.sexp))) + (:include png_write_c_flags.sexp) -O3)) (c_library_flags (:include png_write_c_library_flags.sexp))) diff --git a/io/tiff/dune b/io/tiff/dune index 45d5e506..271b4cd0 100644 --- a/io/tiff/dune +++ b/io/tiff/dune @@ -8,7 +8,7 @@ (language c) (names ReadTiff) (flags - (:include tiff_c_flags.sexp))) + (:include tiff_c_flags.sexp) -O3)) (c_library_flags (:include tiff_c_library_flags.sexp)) (libraries odiff-core WritePng)) diff --git a/odiff-core.opam b/odiff-core.opam index f5cd5069..c997bd0e 100644 --- a/odiff-core.opam +++ b/odiff-core.opam @@ -1,5 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" +version: "0.3.1-rc.3" synopsis: "Pixel-by-pixel image difference algorithm" maintainer: ["https://dmtrkovalenko.dev" "dmtr.kovalenko@outlook.com"] authors: ["Dmitriy Kovalenko"] diff --git a/odiff-io.opam b/odiff-io.opam index 477b0ad0..6c178dac 100644 --- a/odiff-io.opam +++ b/odiff-io.opam @@ -1,5 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" +version: "0.3.1-rc.3" synopsis: "Ready to use io for odiff-core" maintainer: ["https://dmtrkovalenko.dev" "dmtr.kovalenko@outlook.com"] authors: ["Dmitriy Kovalenko"] diff --git a/odiff-tests.opam b/odiff-tests.opam index 693b2b65..c514dcd5 100644 --- a/odiff-tests.opam +++ b/odiff-tests.opam @@ -1,5 +1,6 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" +version: "0.3.1-rc.3" synopsis: "Internal package for integration tests of odiff" maintainer: ["https://dmtrkovalenko.dev" "dmtr.kovalenko@outlook.com"] authors: ["Dmitriy Kovalenko"] diff --git a/src/dune b/src/dune index 190fb24b..1573174e 100644 --- a/src/dune +++ b/src/dune @@ -3,3 +3,12 @@ (public_name odiff-core) (flags (-w -40 -w +26))) + +(env + (dev + (flags (:standard -w +42)) + (ocamlopt_flags (:standard -S))) + (release + (ocamlopt_flags (:standard -O3 -rounds 5 -unbox-closures -inline 200 -inline-max-depth 7 -unbox-closures-factor 50)))) + +