Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MuPDF: fix build #1586

Merged
merged 1 commit into from
Feb 20, 2023
Merged

MuPDF: fix build #1586

merged 1 commit into from
Feb 20, 2023

Conversation

benoit-pierre
Copy link
Contributor

@benoit-pierre benoit-pierre commented Feb 19, 2023

Patch the makefile link command so the build process does not try to link with system libraries (e.g. -lpeg), even when building the generator helpers (like cnamedump.exe). Since mupdf's build system is only in charge of building a static library, we can just drop the $(LIBS) part of the link command.


This change is Reviewable

@benoit-pierre
Copy link
Contributor Author

I could reproduce the CI failure locally after moving my system JPEG library out of the way.

@benoit-pierre
Copy link
Contributor Author

On a semi-related note, because cmake is hell, I've got a meson POC build system, if there's some interest. It does make composing things and experimenting much easier.

@NiLuJe
Copy link
Member

NiLuJe commented Feb 19, 2023

Now that meson finally hit 1.0, and that we don't really care about native win32 anymore... I really, really, really wouldn't be opposed to it (despite my hangups about its approach to cross compilation), despite the potential disruption... RFC, though ;).

@benoit-pierre
Copy link
Contributor Author

Current state: compile the emulator on Linux, cross compile the emulator for Windows (win64, which I managed to get running with some issues, but not anymore with the recent mmap dependency in the partial rendering code), and the kindlepw2 build. Includes release & debug variants, and a mode where most libraries are merged into one big libkoreader. Also included, MuPDF updated to the latest version (I was investigating why the Windows version PDF support does not work).

@poire-z
Copy link
Contributor

poire-z commented Feb 19, 2023

That's impressive ! and a bit frightening as I don't like my living room to be that revamped :)

and a mode where most libraries are merged into one big libkoreader

Part of my dev worklow, after testing on the emulator, is building only libcrengine.so + libkoreader-cre.so for arm (+ their deps), and move them (only these 2 libs) over a recent koreader-kobo nightly on my device to test.
Given my old & slow & space limited build system, having to rebuild the whole libraries for arm each time there is a unrelated thirdparty bump would be quite bothering to me :/

@Frenzie
Copy link
Member

Frenzie commented Feb 19, 2023

On a semi-related note, because cmake is hell, I've got a meson POC build system, if there's some interest. It does make composing things and experimenting much easier.

Yes, absolutely.

cross compile the emulator for Windows (win64, which I managed to get running with some issues

Cool!

@benoit-pierre
Copy link
Contributor Author

That's impressive ! and a bit frightening as I don't like my living room to be that revamped :)

and a mode where most libraries are merged into one big libkoreader

Part of my dev worklow, after testing on the emulator, is building only libcrengine.so + libkoreader-cre.so for arm (+ their deps), and move them (only these 2 libs) over a recent koreader-kobo nightly on my device to test. Given my old & slow & space limited build system, having to rebuild the whole libraries for arm each time there is a unrelated thirdparty bump would be quite bothering to me :/

Yeah, it does increase the base memory use, even if it potentially decreases the maximum memory needed when all the shared libraries are loaded. It does help taking advantage of LTO to further optimize and trim unused symbols.

Anyway, it's optional ;)

@poire-z
Copy link
Contributor

poire-z commented Feb 19, 2023

Anyway, it's optional ;)

Well, if the performance improvment is noticable, we'll have to decide how to go with building nightlies & stable. And we would loose quite a bit of practicality with a monolithic libkoreader.so (like shipping debug/test libs to users).
Also, how would we handle stuff like ffi.load("libs/libgif.so.7") ? We'd have many new codepaths for when monolibtic mode is enabled vs not?
And if we need that many tweaks to frontend and base/ffi to handle both modes, it will be quite bothering and the need to update & test both modes when adding new stuff :/ so, we'll end up killing one of these, and it won't be optionnal :)

Patch the makefile link command so the build process does not try
to link with system libraries (e.g. `-lpeg`), even when building
the generator helpers (like `cnamedump.exe`). Since mupdf's build
system is only in charge of building a static library, we can just
drop the `$(LIBS)` part of the link command.
@benoit-pierre
Copy link
Contributor Author

benoit-pierre commented Feb 19, 2023

Meson POC available here: koreader, koreader-base, and crengine.

Notes:

  • only tested on Linux
  • support ./kodev build & ./kodev run to build/run the emulator
  • support ./kodev build kindlepw2 (curl, sftp-server & zsync2 not yet included, sscache use is forced, see meson/cross_kindlepw2.txt)
  • support ./koded build win64 & ./kodev run win64 to cross-compile for Windows (wine is used for running, see meson/cross_emulator_win64.txt)
  • subprojects are used for thirdparty dependencies: patches and overlay trees are in subprojects/packagefiles, download cache in subprojects/packagecache
  • thirdparty dependency source trees are under subprojects, removed on make dist-clean
  • build output is stored under ./build
  • install directories in top dir (e.g.: koreader-emulator_linux-debug)
  • when building the emulator on Linux, some directories are symlinked to the install directory, otherwise everything is copied
  • no more rocks directory, everything is under common
  • amalgam mode (one big libkoreader library) can be enabled by setting KOAMALGAM=1 in the environment (a different build/install directory will automatically be used)
  • build options are in ./meson:
    • options.txt: common options
    • options_amalgam.txt: override for amalgam mode
    • options_debug.txt: debug build options
    • options_release.txt: ditto for release
    • target_xxx.txt: target specific options
    • cross_xxx.txt: cross-compiling options

TODO:

  • add curl, openssh, zsync
  • see if an Android build is feasible? I've not even tried it with the standard build system
  • rename amalgam mode to monolibtic ;)
  • switch from archives to git clones (the former was faster for developing/testing the build system, but using
    checkouts would make patch management easier)

Well, if the performance improvment is noticable, we'll have to decide how to go with building nightlies & stable. And we would loose quite a bit of practicality with a monolithic libkoreader.so (like shipping debug/test libs to users).
Also, how would we handle stuff like ffi.load("libs/libgif.so.7") ? We'd have many new codepaths for when monolibtic mode is enabled vs not?
And if we need that many tweaks to frontend and base/ffi to handle both modes, it will be quite bothering and the need to update & test both modes when adding new stuff :/ so, we'll end up killing one of these, and it won't be optional :)

I've added a ffi.loadlib function to simplify loading libraries (see SDL
example
): it takes a series of (library name, optional version) pair to look for, and the loadlib helper handle looking for the right library and abstracting the details of the platform specifics prefix/suffix.

When building in monolibtic mode, a small lua file is generated and used by setupkoenv to handle overrides: redirect some requires and ffi.loadlib calls to libkoreader. Here is the content of the generated file:

return {
    library = 'libs/libkoreader.so',
    preloads = {
        ["libs/libkoreader-cre"] = "luaopen_cre",
        ["libs/libkoreader-djvu"] = "luaopen_djvu",
        ["libs/libkoreader-nnsvg"] = "luaopen_nnsvg",
        ["libs/libkoreader-xtext"] = "luaopen_xtext",
    },
    redirects = {
        ["czmq.1"] = true,
        ["freetype.6"] = true,
        ["harfbuzz.0"] = true,
        ["k2pdfopt.2"] = true,
        ["lept.5"] = true,
        ["lodepng"] = true,
        ["mupdf"] = true,
        ["sqlite3.0"] = true,
        ["utf8proc.2"] = true,
        ["z"] = true,
        ["zmq.4"] = true,
        ["zstd.1"] = true,
        ["SDL2-2.0.0"] = true,
        ["wrap-mupdf"] = true,
        ["blitbuffer"] = true,
    },
}

@NiLuJe
Copy link
Member

NiLuJe commented Feb 20, 2023

At a very quick glance, that looks rather sexy ;).

I can certainly see the appeal of mesonifying everything to sidestep annoying upstream buildsystems, too... Is there a tool that helps generate meson.build files or was that a lot of hand-made tweaking?

@eli-schwartz
Copy link

eli-schwartz commented Feb 20, 2023

Oh neat.

despite my hangups about its approach to cross compilation

@NiLuJe BTW -- nifty little trick, you can actually trigger a cross compilation like this: CC=my-cross-gcc CXX=my-cross-g++ meson setup builddir --cross-file=/dev/null.

Practically everything from a cross file is not actually necessary, if that's what you were referring to. (And the one thing you officially do "need" you can still do without.)

@poire-z
Copy link
Contributor

poire-z commented Feb 20, 2023

I can't judge about the build system change and pros/cons, I'm not competent enough - but it indeed looks more readable than CMake.
A bit confused about what gets in koreader frontend and what in koreader-base - and what controls what - but I guess I'll learn. Would we still need the 2 repos koreader + koreader-base ?

Some practical questions, just to get an idea how complicated it would get for me :/:

  • could we still use our (possibly old, still using gcc-arm from debian10 on my debian11) crosscompiling toolchain ? Or does meson (and/or your upgraded stuff) requires up to date crosstools ? And would it work on current debian 11 tools, or would you require us to have to build newer versions of most of the build tools ? :/
  • could I still build all of it on my small headless linux with 4GB or RAM (3GB free) ? How much memory would the monolibtic build need ?
  • (not really happy with having Windows support: now, when we add a feature using Linux specific stuff, we would be required to code the Windows counterpart and know about Windows API... which I promise I will not learn ! :)

@poire-z
Copy link
Contributor

poire-z commented Feb 20, 2023

And btw... who are you ?!
Out of nowhere, you pop in, and:

  • bump MuPDF, that no one really dared doing for years (didn't look like it needed much work though :)
  • kill the dragon CMake
  • bring Windows support

What next ? I'm a bit fearing you might rewrite crengine in rust :/
Why such interest in KOReader ? Long time user ? Do you have time to read ? :)

@NiLuJe
Copy link
Member

NiLuJe commented Feb 20, 2023

@NiLuJe BTW -- nifty little trick, you can actually trigger a cross compilation like this: CC=my-cross-gcc CXX=my-cross-g++ meson setup builddir --cross-file=/dev/null.

Practically everything from a cross file is not actually necessary, if that's what you were referring to. (And the one thing you officially do "need" you can still do without.)

Oh, I like that, thanks!

(Last I checked, there was a very strong assumption that what's in env vars should only ever affect the host, not the target, so, e.g., setting CFLAGS with arm-specific flags in the env would break pretty much anything that required running the host compiler during the build (e.g., code generation tools)).

@eli-schwartz
Copy link

https://mesonbuild.com/Reference-tables.html#environment-variables-per-machine

We support autotools-style $XXX_FOR_BUILD variant variables, though anything in a machine file always trumps the environment. Old versions of Meson may have been a bit messy, though. :(

@Frenzie
Copy link
Member

Frenzie commented Feb 20, 2023

@poire-z

And btw... who are you ?!

On the one hand I don't know either, on the other hand a quick glance comes up with https://github.com/openstenoproject/plover which is an extremely impressive piece of software I've known about for years.

@benoit-pierre I think the bigger question is… where'd you find all the time? 😆 Either that or you can do in hours what would take me at least a full working week. ;-)

@yparitcher
Copy link
Member

If you are updating MuPdf please show a little love to k2pdfopt :)
Our fork with patches is https://github.com/koreader/libk2pdfopt and it and its dependent libraries can only be bumped in tandem with mupdf

@Frenzie
Copy link
Member

Frenzie commented Feb 20, 2023

You probably already saw btw, but #1203 has pretty much all of the work required in it. Specifically see https://github.com/ezdiy/libk2pdfopt

@poire-z
Copy link
Contributor

poire-z commented Feb 20, 2023

Should we merge this PR quickly, for master to build ? (that is, if you approve the changes)

@Frenzie Frenzie merged commit 564429f into koreader:master Feb 20, 2023
@benoit-pierre benoit-pierre deleted the pr/fix_mupdf_build branch February 21, 2023 11:50
@benoit-pierre
Copy link
Contributor Author

I can certainly see the appeal of mesonifying everything to sidestep annoying upstream buildsystems, too... Is there a tool that helps generate meson.build files or was that a lot of hand-made tweaking?

100% organic made.

Part of my dev worklow, after testing on the emulator, is building only libcrengine.so + libkoreader-cre.so for arm (+ their deps), and move them (only these 2 libs) over a recent koreader-kobo nightly on my device to test.
Given my old & slow & space limited build system, having to rebuild the whole libraries for arm each time there is a unrelated thirdparty bump would be quite bothering to me :/

# manually setup for `remarkable` (no `monolibtic`) without building
▸ make KODEBUG=1 TARGET=remarkable setup
# rebuild only libkoreader-cre.so and dependencies (about ~500 targets).
▸ ninja -C build/remarkable-debug libkoreader-cre.so
# copy to target device
▸ scp build/remarkable-debug/libkoreader-cre.so …

There's no libcrengine.so anymore: it's always statically built, since libkoreader-cre is the only user. Same with some of its dependencies: antiword, chmlib and lunasvg.

This take about 140s on my (10 years old) machine, starting from a cold compile cache. As for space, compared to the current stats on master, with (almost) the same builds:

subprojects/ 987M
build/emulator_linux/ 316M
build/emulator_linux-debug/ 628M
build/kindlepw2/ 292M
build/ 1.3G
TOTAL 2.2G

I can't judge about the build system change and pros/cons, I'm not competent enough - but it indeed looks more readable than CMake.
A bit confused about what gets in koreader frontend and what in koreader-base - and what controls what - but I guess I'll learn. Would we still need the 2 repos koreader + koreader-base ?

Meson impose the location of sub-projects, so base/thirdparty would be gone, as well as:

  • base/Makefile
  • base/Makefile.defs
  • base/Makefile.third
  • base/luafilesystem/ & base/patches/ (the later contains one patch for luafilesystem)

That still leaves quite a few things:

  • the source for all helper libraries: libblitbuffer, libkoreader-cre, libkoreader-djvu, …
  • FFI stuff (ffi/ & ffi-cdecl/)
  • and some miscellaneous stuff: PDF helpers (extr & utils/), utils/ (Android toolchain install helper), …

I certainly would welcome less git submodules (always a PITA to deal with).

Some practical questions, just to get an idea how complicated it would get for me :/:

could we still use our (possibly old, still using gcc-arm from debian10 on my debian11) crosscompiling toolchain ?

I don't see why not.

Or does meson (and/or your upgraded stuff) requires up to date crosstools ? 

I don't think so.

And would it work on current debian 11 tools, or would you require us to have to build newer versions of most of the build tools ? :/

could I still build all of it on my small headless linux with 4GB or RAM (3GB free) ? How much memory would the monolibtic build need ?

Again, "monolibtic" mode is optional, and the LTO stuff can be disabled in meson/options_release.txt. I don't know about memory usage, but linking the monolibtic libkoreader for kindlepw2 with LTO does take a good 5 minutes on my machine… Which I think is probably a combination of older GCC version and non-optimized build: I'm using the latest koxtoolchain release, I haven't managed to rebuild one with gen-tc.sh, yet alone attempted to update the GCC version.

(not really happy with having Windows support: now, when we add a feature using Linux specific stuff, we would be required to code the Windows counterpart and know about Windows API... which I promise I will not learn ! :)

That's was really more of quick way to test cross-compiling for another platform (and the ffi.loadlib stuff). It's broken anyway (mmap, PDF support, subprocess handling). There's also a subtle bug with CRE documents, see if you can spot it:

2023-02-21-200900_540x720_scrot

I also have no love for Windows, so I'm going to drop it.

Why such interest in KOReader ? Long time user ? Do you have time to read ? :)

User, yes. Reading times have recently plummeted..

If you are updating MuPdf please show a little love to k2pdfopt :) […]

I've just done the minimum for sanity's sake (see subprojects/packagefiles/libk2pdfopt/less_fugly.patch) for now.

[…] its dependent libraries can only be bumped in tandem with mupdf

  1. mupdf depends on freetype2, harfbuzz, libjpeg, libwebpdemux, and some modified thirdparty libraries: gumbo-parser, jbig2dec, mujs & openjp2
  2. libk2pdfopt depends on leptonica & tessact
  3. tesseract depends on leptonica
  4. and leptonica optionally depends on libopenjp2, libjpeg, libpng, libtiff-4 & libwebp: right now I'm only enabling PNG support as analyzing the list of symbols required by Koreader does not show the need for anything else.

You probably already saw btw, but #1203 has pretty much all of the work required in it. Specifically see https://github.com/ezdiy/libk2pdfopt

Yeah, I've not looked into it yet. What would be helpful is a checklist of tests to ensure everything is indeed working as expected: with so many options, it's hard to know if I've hit all the code paths (like the support for highlighting).

Tentative list:

  • PDF support:
    • opening a PDF
    • selecting some text (check multi-lines)
    • highlighting selection
    • changing an highlight style
    • deleting an highlight
    • saving highlights? I've noticed Koreader ask if changes must be saved, but even after declining, there's still some state saved (even on master).
    • what else? encryption support, external fonts, …
  • CBZ support:
    • opening a comic
    • try zooming on a panel (long press)
  • HTML support:
    • check the results of a dictionary lookup

@eli-schwartz
Copy link

still using gcc-arm from debian10 on my debian11) crosscompiling toolchain ? Or does meson (and/or your upgraded stuff) requires up to date crosstools ? And would it work on current debian 11 tools, or would you require us to have to build newer versions of most of the build tools ? :/

@poire-z,

Meson's CI regularly tests Ubuntu Bionic, which is older than those, and has GCC 7.4; in general, there's no need to worry about using the environment of a still supported, much less quite recent, distro.

...

As a generic rule?

Meson tries to avoid arbitrarily restricting the version of your compiler, but in order to integrate well it does sometimes need to know how to activate features. Meson usually version guards this when added, and doesn't gratuitously drop support for old compilers (and we literally cannot drop support for 7.4, since, again, we target that in our CI). There is support code as old as 4.8, which is the first version of GCC released after Meson was started (it handles warning arguments). I do not know whether anyone still relies on it, but there's no plan to drop that either, since it already exists and isn't a burden to leave in place.

Any given user probably does not need GCC 2.x support. If you did, Meson would probably be a bad choice, because Meson makes no effort to support systems or toolsets that were ancient and obsolete before it was started. :P

@NiLuJe
Copy link
Member

NiLuJe commented Feb 22, 2023

yet alone attempted to update the GCC version.

That's near the top of my TODO list, FWIW (I'll hopefully get to it in the next couple of months...).

Not that it'll help much with the speed of LTO linking, the only really faster alternatives I know of are Clang in thin-lto mode, coupled with lld or even (or especially, I should say ^^) mold ;).

@NiLuJe
Copy link
Member

NiLuJe commented Feb 22, 2023

I do not know whether anyone still relies on it

(re: gcc 4.8)

That's (nearly? can't remember the exact cutoff) the last GCC version licensed under GPL v2, so, that's what the GCC version available in (old) Android NDKs is based on (and we haven't made the move to Clang yet there). Or, even, for the same licensing reasons, some really old OS X toolchains, if you're feeling mad ;D.

@eli-schwartz
Copy link

eli-schwartz commented Feb 22, 2023

Sounds painful, but if you do need it and you run into issues with it, I am happy to merge untested PRs on the honor system, that support such old GCCs better. (It will probably just work with fewer optional features though.)

some really old OS X toolchains, if you're feeling mad ;D.

... for which definition of mad? 👀

@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

diff --git a/setupkoenv.lua b/setupkoenv.lua
index be1b2e228..37af263d9 100644
--- a/setupkoenv.lua
+++ b/setupkoenv.lua
@@ -15,7 +15,7 @@ if ffi.os == "Windows" then
 end
 local ffi_load = ffi.load
 -- patch ffi.load for thirdparty luajit libraries
-ffi.load = function(lib)
+ffi.load = function(lib, global)
     io.write("ffi.load: ", lib, "\n")
     local loaded, re = pcall(ffi_load, lib)
     if loaded then return re end
@@ -27,6 +27,6 @@ ffi.load = function(lib)
         error("Not able to load dynamic library: " .. lib)
     else
         io.write("ffi.load (assisted searchpath): ", lib_path, "\n")
-        return ffi_load(lib_path)
+        return ffi_load(lib_path, global)
     end
 end

should fix it.

@benoit-pierre
Copy link
Contributor Author

Of course! That must be it.

NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jul 17, 2023
We *do* actually use the optional global argument sometime...
Namely, for librt in ffi/posix_h.
c.f., koreader/koreader-base#1586 (comment)
@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

Added that to koreader/koreader#10705 because why not ;D.

@poire-z
Copy link
Contributor

poire-z commented Jul 17, 2023

Confirmed that it solves it without needing any require("ffi/posix_h").
In @benoit-pierre version, near the bottom:

else
    ffi.load = function(lib, global)
        log("ffi.load: " .. lib)
        return ffi_load(lib, global)
    end
end

the ffi.load overload somehow breaks the fancy RTLD_GLOBAL load... because it doesn't take enough arguments

So, that means 1) there is a global table named global in Lua :) and 2) ffi.load(lib, global) puts into it some variable the library exposes as "being global" ?!

@benoit-pierre
Copy link
Contributor Author

benoit-pierre commented Jul 17, 2023

[…]
-- and just for me, make my own modules available (dunno where it is set in your build)
package.path = package.path .. ";/mnt/onboard/.adds/mykoreader/modules/?.lua"

In the build options, e.g:

@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

@poire-z:

c.f., ld(1)

        RTLD_GLOBAL
               The symbols defined by this shared object will be made available for symbol resolution of subsequently loaded shared objects.

In LuaJIT, it's the default for require (i.e., Lua/C modules), but not for ffi.load.

(Require also does full symbol resolution on load via RTLD_NOW, while ffi.load only does lazy resolution via RTLD_LAZY).

@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

In a way, thanks for confirming that we did indeed need it in the global namespace, because I had never actually tested this ;D.

@poire-z
Copy link
Contributor

poire-z commented Jul 17, 2023

Btw, which explicite ffi.load() where then benefits from this fix so that C.clock_getres is then found?
Or is it require("ffi/posix_h") which implicitely ffi.load()s libc.so or librt.so ?

@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

This one:

-- clock_gettime & friends require librt on old glibc (< 2.17) versions...
if ffi.os == "Linux" then
-- Load it in the global namespace to make it easier on callers...
-- NOTE: There's no librt.so symlink, so, specify the SOVER, but not the full path,
-- in order to let the dynamic loader figure it out on its own (e.g., multilib).
pcall(ffi.load, "rt.so.1", true)
end

If you require'ed ffi/posix.h before (or early in) setupkoenv, it was using the stock ffi.load function (which obviously honors global), if not, it was using our overload from setupkoenv, which ignored global.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

(I double-checked, that's our only ffi.load that sets global ^^).

@poire-z
Copy link
Contributor

poire-z commented Jul 17, 2023

OK, so global is not the Lua table of global variables, but a bool :)
And this "global namespace" is actually ffi.C. https://luajit.org/ext_ffi_api.html

And I assume no need to ffi.load("libc"), and that the other symbols from libc are put there by LuaJIT:

On POSIX systems, this binds to symbols in the default or global namespace. This includes all exported symbols from the executable and any libraries loaded into the global namespace. This includes at least libc, libm, libdl (on Linux), libgcc (if compiled with GCC),

@poire-z
Copy link
Contributor

poire-z commented Jul 17, 2023

Btw, no speedup noticed in my usual benchmark test (a French Bible EPUB with > 1000 fragments), same times (30s loading + 12s rendering with no cache, 3s loading + 23s rerendering if cache rendering hash mistmatch) whether latest nightly or this monolibtic on my Kobo.

@benoit-pierre
Copy link
Contributor Author

Btw, no speedup noticed in my usual benchmark test (a French Bible EPUB with > 1000 fragments), same times (30s loading + 12s rendering with no cache, 3s loading + 23s rerendering if cache rendering hash mistmatch) whether latest nightly or this monolibtic on my Kobo.

Note that the CI kindlepw2 and kobo build use buildtype = 'minsize' (-Os), so what about memory use?

@poire-z
Copy link
Contributor

poire-z commented Jul 17, 2023

Not enough time with it to see how it grows (it's possible I've seen it at 100M earlier before I installed today's nightly, but not sure).
But a startup now (starting into a 150 pages EPUB) with our nightly and after start our footer mem indicator says 40M. With your monolibtic it says 50M.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 17, 2023

I imagine you'll probably want to open both an ePub and a PDF to make the test fair?

@poire-z
Copy link
Contributor

poire-z commented Jul 17, 2023

Given that PDF gets BB of page cached in memory, it's not easy to distinguish the memory used by the app vs. what is cached.
Broswing and siwtching EPUBs is the real test for memory leaks :)

NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jul 17, 2023
We *do* actually use the optional global argument sometime...
Namely, for librt in ffi/posix_h.
c.f., koreader/koreader-base#1586 (comment)
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Jul 17, 2023
We *do* actually use the optional global argument sometime...
Namely, for librt in ffi/posix_h.
c.f., koreader/koreader-base#1586 (comment)
NiLuJe added a commit to koreader/koreader that referenced this pull request Jul 18, 2023
We *do* actually use the optional global argument sometime...
Namely, for librt in ffi/posix_h.
c.f., koreader/koreader-base#1586 (comment)
@poire-z
Copy link
Contributor

poire-z commented Jul 18, 2023

Just a note, as I don't think there's anything we can do as it feels upstream, but newer MuPDF seems worse with some HTML than our current one:

image
(In the MuPDF 1.22 view, some stuff logically after the pink box is drawn above it. Possibly some block element among inlines that get pushed after them.)

This is the nice rendering I currently get with KOReader (including the 2nd definition that is missing in the MuPDF 1.13 above):

image

@Frenzie
Copy link
Member

Frenzie commented Jul 18, 2023

What's the CSS? Could be nicer by accident. :)

@poire-z
Copy link
Contributor

poire-z commented Jul 18, 2023

No CSS involved. Just the html result (which has some style= attributes):
diabolique.html.txt
(to which I have a dict.lua that does some massage, but it doesn't change anything to the result:
outdict.html.txt )
Anyway, I'll think about massaging it more in that dict.lua once we'll have this newer MuPDF :)

@Frenzie
Copy link
Member

Frenzie commented Jul 18, 2023

It does look like the older MuPDF may be listening to display: inline and the newer isn't? Curious.

<div style="margin-top: 15pt; margin-left: 20pt; margin-bottom: 15pt; text-indent: -15pt; display: inline"><span style="background-color: rgb(69,86,130); color: red; border: solid 1px gray; zzz: Verdana; font-size: xx-small; font-weight: bold"><span> 1 </span></span> </div>

@poire-z
Copy link
Contributor

poire-z commented Jul 21, 2023

Wanted to "fix" this dict.lua, so downloaded the AppImage from https://github.com/benoit-pierre/koreader/actions/runs/5578752636 v2023.04-8083-g36de7a303_2023-07-17.AppImage
When extracted and run on my Linux (old hardware, maybe you put cpu optimisations/flags my Intel(R) Celeron(R) CPU 847 @ 1.10GHz doesn't support?):

has libkoreader? yes
lib_search_path: libs/?
lib_basic_format: lib%s.so
lib_version_format: lib%s.so.%s
Illegal instruction

under gdb:
Program received signal SIGILL, Illegal instruction.
0x00007ffff65950b9 in ?? () from libs/libkoreader.so
(gdb) p
The history is empty.
(gdb) bt
#0  0x00007ffff65950b9 in ?? () from libs/libkoreader.so
#1  0x00007ffff7fcfabe in call_init (env=0x7fffffffdc90, argv=0x7fffffffdc78, argc=2, l=<optimized out>) at ./elf/dl-init.c:70
#2  call_init (l=<optimized out>, argc=2, argv=0x7fffffffdc78, env=0x7fffffffdc90) at ./elf/dl-init.c:26
#3  0x00007ffff7fcfba4 in _dl_init (main_map=0x555555615a50, argc=2, argv=0x7fffffffdc78, env=0x7fffffffdc90) at ./elf/dl-init.c:117
#4  0x00007ffff7e47e44 in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:182
#5  0x00007ffff7fd630e in dl_open_worker (a=a@entry=0x7fffffffd4b0) at ./elf/dl-open.c:808
#6  0x00007ffff7e47dea in __GI__dl_catch_exception (exception=<optimized out>, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#7  0x00007ffff7fd66a8 in _dl_open (file=0x7ffff7cb9818 "libs/libkoreader.so", mode=<optimized out>, caller_dlopen=0x5555555ee82a, nsid=<optimized out>, argc=2, argv=0x7fffffffdc78,
    env=0x7fffffffdc90) at ./elf/dl-open.c:884
#8  0x00007ffff7d7e2d8 in dlopen_doit (a=a@entry=0x7fffffffd720) at ./dlfcn/dlopen.c:56
#9  0x00007ffff7e47dea in __GI__dl_catch_exception (exception=exception@entry=0x7fffffffd680, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#10 0x00007ffff7e47e9f in __GI__dl_catch_error (objname=0x7fffffffd6d8, errstring=0x7fffffffd6e0, mallocedp=0x7fffffffd6d7, operate=<optimized out>, args=<optimized out>)
    at ./elf/dl-error-skeleton.c:227
#11 0x00007ffff7d7ddc7 in _dlerror_run (operate=operate@entry=0x7ffff7d7e280 <dlopen_doit>, args=args@entry=0x7fffffffd720) at ./dlfcn/dlerror.c:138
#12 0x00007ffff7d7e389 in dlopen_implementation (dl_caller=<optimized out>, mode=<optimized out>, file=<optimized out>) at ./dlfcn/dlopen.c:71
#13 ___dlopen (file=<optimized out>, mode=<optimized out>) at ./dlfcn/dlopen.c:81
#14 0x00005555555ee82a in ?? ()
#15 0x00005555555d3d02 in ?? ()
#16 0x00005555555f38a6 in ?? ()
#17 0x00005555555ded63 in ?? ()
#18 0x00005555555f38a6 in ?? ()
#19 0x00005555555df0c8 in ?? ()
#20 0x00005555555f38a6 in ?? ()
#21 0x0000555555577a73 in lua_pcall ()
#22 0x0000555555563203 in ?? ()
#23 0x00005555555685c4 in ?? ()
#24 0x00005555555f38a6 in ?? ()
#25 0x0000555555577ac1 in lua_cpcall ()
#26 0x000055555555c812 in main ()

@Frenzie
Copy link
Member

Frenzie commented Jul 21, 2023

You confused me there — you're not talking about "my" AppImage build but some experimental Meson build. :-) We use -mtune=generic -march=x86-64 which I occasionally test on my old Intel Atom netbook.

@poire-z
Copy link
Contributor

poire-z commented Jun 1, 2024

As expected with the MuPDF update, HTML dict users can now meet the crappier HTML rendering mentionned above at #1586 (comment) :/

I guess it can only be worked around by massaging the HTML in each dict specific .lua tweak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants