Skip to content

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

Open
namana-mecha wants to merge 2 commits intomecha-org:devfrom
namana-mecha:text-rendering-issue
Open

bug-fix(font-cache): Eliminated unwanted cloning of cosmic_text::fontdb::Database by passing it as a reference#71
namana-mecha wants to merge 2 commits intomecha-org:devfrom
namana-mecha:text-rendering-issue

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