Skip to content

Conversation

@Its-Just-Nans
Copy link
Contributor

@Its-Just-Nans Its-Just-Nans commented Dec 13, 2025

This is more like a Proof of concept about not writing nodes.

But it's very bad great for performance

let mut fake_xml = XmlWriter::new(Options::default());
write_group_element(g, is_clip_path, opt, &mut fake_xml);
let fake_xml_str = fake_xml.end_document();
if fake_xml_str != "<g/>\n" {
    write_group_element(g, is_clip_path, opt, xml);
}

@Its-Just-Nans
Copy link
Contributor Author

Any others ideas to not write empty nodes ?

@Its-Just-Nans
Copy link
Contributor Author

Its-Just-Nans commented Dec 13, 2025

I'm also thinking on "start_svg_element" only when necessary, ie

Before

xml.start_svg_element(EId::G);
if !g.id.is_empty() {
    xml.write_id_attribute(&g.id, opt);
};
// ...
xml.end_element();

After

let mut element_started = false;
if !g.id.is_empty() {
    xml.start_svg_element(EId::G);
    element_started = true;
    xml.write_id_attribute(&g.id, opt);
};

// ...
if element_started {
    xml.end_element();
}

@Its-Just-Nans
Copy link
Contributor Author

Hi @LaurenzV pinging you for question

Do you think the second option ("after") is suitable?

@LaurenzV
Copy link
Collaborator

I'm not sure... But I can't say I'm a fan, to be honest. I'll try to think about it a bit more when I find some time.

@LaurenzV
Copy link
Collaborator

Probably there should be some method that based on the group node checks whether it will be empty, and then only do the check once. Otherwise, we would have to do the check every time we write a new attribute.

@Its-Just-Nans
Copy link
Contributor Author

I'm not sure... But I can't say I'm a fan, to be honest. I'll try to think about it a bit more when I find some time.

I implemented the lazy writer version. What do you think about 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.

2 participants