Skip to content

Add dynamic linking support #1420

@axelkar

Description

@axelkar

Steps:

  1. Rename xilem to xilem-internal
  2. Create xilem with pub use xilem_internal::*;.
  3. Create xilem-dylib with [lib] crate-type = ["dylib"] in Cargo.toml and use xilem_internal; in lib.rs.
  4. Add a feature to xilem to enable the xilem-dylib dependency and use xilem_dylib;.

This can also be made work without creating a new xilem-internal package by making package consumers add use xilem_dylib; themselves.

This makes the program depend on Xilem via a dynamic library instead of statically linking:

$ ldd target/debug/myapp | rg xilem
        libxilem_dylib.so => not found
$ du -sh target/debug/myapp target/debug/libxilem_dylib.so
41M     target/debug/myapp
338M    target/debug/libxilem_dylib.so

For me, this reduced incremental compilation times (simple app) from ~1.75s to ~0.95s. That's -45%.

Dynamically linking dioxus-devtools and winit over made the incremental compilation time drop further down to 0.87s and produced this:

$ ldd target/debug/myapp | rg xilem
        libxilem_dylib.so => not found
$ du -sh target/debug/myapp target/debug/libxilem_dylib.so
26M     target/debug/myapp
358M    target/debug/libxilem_dylib.so

Without dynamic linking, the linker can remove more unused code and perform other optimizations.

$ ldd target/debug/myapp | rg xilem
        libxilem_dylib.so => not found
$ du -sh target/debug/myapp
317M     target/debug/myapp

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions