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

bug-fix(font-cache): Eliminated unwanted cloning of cosmic_text::fontdb::Database by passing it as a reference #71

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

namana-mecha
Copy link
Contributor

Objective

Fixes #70

Solution

cosmic_test::fontdb::Database was being cloned which was fixed by passing the FontCache itself as a mutable reference and making the changes accordingly.

Before

    fn caches(&self) -> Caches {
        Caches {
            font: Arc::new(RwLock::new(FontCache::new(self.fonts.clone()))),
        }
    }

After

    fn caches(&mut self) -> Caches {
        Caches {
            font: Arc::new(RwLock::new(&mut self.fonts_cache)),
        }
    }

Testing

Flamegraph of the code after the fix

image

…tdb::Database` by passing it as a reference.
@shoaibmerchant
Copy link
Member

Nice work @namana-mecha can you address the comment, this might cause a lock condition

- The calculation of layout takes a mutable reference to the `FontCache`
in ui.rs. This commit will add a comment explaining the reasoning behind
it.
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.

Excessive Cloning Detected in Flamegraph Profiling
2 participants