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

Optimise atom_manager! implementation #914

Merged
merged 2 commits into from
Feb 15, 2024
Merged

Commits on Feb 3, 2024

  1. Optimise atom_manager! implementation

    winit uses atom_manager! with 59 atom names. Due to some sub-optimal
    code generation, this causes the generated new() function to end up with
    a size of 111.6 KiB, or almost 5% of the .text size of a winit example.
    
    The issue is that each "intern_atom()?" can cause an early exit and
    needs to call drop() of the already generated Cookies. This leads to
    some quadratic growth.
    
    To work around this, in this commit I change the implementation of
    new(). It now iterates over the atom names, using .map() to send the
    InternAtom requests. Finally, collect() is then used to change this
    Iterator<Item=Result<Cookie, Error>> into Result<Vec<Cookie>, Error>.
    This even preserves the early-exit behaviour in case of errors.
    
    The reply() function is then changed to turn the Vec into an iterator,
    using next() to pull out the items. This relies on the evaluation of
    this code to be well-defined (which e.g. wouldn't be guaranteed in C).
    Luckily, Rust provides the needed guarantee:
    rust-lang/reference#888
    
    Fixes: #912
    Signed-off-by: Uli Schlachter <psychon@znc.in>
    psychon committed Feb 3, 2024
    Configuration menu
    Copy the full SHA
    39be186 View commit details
    Browse the repository at this point in the history

Commits on Feb 5, 2024

  1. Test & fix atom_manager! macro hygiene

    This makes sure that the macro refers to standard types in an
    unambiguous way that does not use types from the local module. Instead,
    a full path beginning with "::std" is used.
    
    Thanks to @notgull for pointing this out.
    
    Signed-off-by: Uli Schlachter <psychon@znc.in>
    psychon committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    f431b67 View commit details
    Browse the repository at this point in the history