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

Send parameterizable rewriter #224

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

orium
Copy link
Member

@orium orium commented Sep 10, 2024

Some data structures had to be turned into Sync to make the rewriter Send (if the handlers are Send). This has a performance penalty even when using a non-Send rewriter.

The benchmarks have a median slowdown of -0.8%. You read that right: a negative slowdown, which is a speedup. This can only be explained by noise while running the benchmarks, as they can only get slightly slower, not faster. However, it shows that the performance change is negligible (in my x86 machine, at least).

@orium orium force-pushed the send-parameterizable-rewriter branch 2 times, most recently from eaa561a to abace12 Compare September 17, 2024 14:06
// implementations of `HandlerTypes`, so each implementation of `HandlerTypes` needs to prove
// that a handler compatible with itself is creatable.

fn new_end_tag_handler<'h>(
Copy link
Member Author

@orium orium Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still working at improving these methods.

edit: done (not much can be improved I think)

@orium orium force-pushed the send-parameterizable-rewriter branch 5 times, most recently from df1d4ac to 5feceab Compare September 24, 2024 08:44
@orium orium marked this pull request as ready for review September 24, 2024 08:47
@orium orium changed the title [WIP] Send parameterizable rewriter Send parameterizable rewriter Sep 24, 2024
@@ -371,9 +380,41 @@ mod tests {
out
}

#[allow(clippy::drop_non_drop)]
#[test]
fn handlers_covariance() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this test? It doesn't seem to have any assertions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks the the handlers continue to be covariant, that is, if you have a handler with a lifetime larger than 'a you can put that handler in a place where a lifetime of 'a is expected.

The test doesn't assert anything because it is a "if it compile it is good". If the handlers stopped being covariant in their lifetime it test would not compile.

I'll add some comments.

@@ -13,7 +13,7 @@ define_group!(

Ok(())
})],
..Settings::default()
..Settings::new()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this to new?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settings::new() creates settings for a non-Send rewriter (that is, it creates a Settings<'_, '_, HandlerNormalTypes>).

Settings::new_send() creates settings for a Send rewriter (that is, it creates a Settings<'_, '_, HandlerSendTypes>).

Settings::default() also creates settings for a non-Send rewriter, just like Settings::new().

The reason I added Settings::new() is because I had to add Settings::new_send() so it would make sense to also have Settings::new() as well.

src/lib.rs Outdated
@@ -37,12 +37,49 @@ use cfg_if::cfg_if;

pub use self::rewriter::{
rewrite_str, AsciiCompatibleEncoding, CommentHandler, DoctypeHandler, DocumentContentHandlers,
ElementContentHandlers, ElementHandler, EndHandler, EndTagHandler, HandlerResult, HtmlRewriter,
MemorySettings, RewriteStrSettings, Settings, TextHandler,
ElementContentHandlers, ElementHandler, EndHandler, EndTagHandler, HandlerNormalTypes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename HandlerSendTypes and HanderNormalTypes to SendHandlerTypes and LocalHandlerTypes

) -> Self::ElementHandler<'h>;

/// Creates a handler by running multiple handlers in sequence.
fn combine_handlers(handlers: Vec<Self::EndTagHandler<'_>>) -> Self::EndTagHandler<'_>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be used only internally, should we use #[doc(hidden)]?

impl<E: ElementData> SelectorMatchingVm<E> {
impl<E: ElementData> SelectorMatchingVm<E>
where
E: Send,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move ElementData to the where clause

@orium orium force-pushed the send-parameterizable-rewriter branch from 5feceab to 72656cc Compare September 24, 2024 10:15
@inikulin inikulin merged commit 3789fe4 into cloudflare:master Sep 24, 2024
5 checks passed
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