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

Remove inline content #765

Merged
merged 1 commit into from
Sep 5, 2024
Merged

Remove inline content #765

merged 1 commit into from
Sep 5, 2024

Conversation

joeldrapper
Copy link
Collaborator

@joeldrapper joeldrapper commented Sep 4, 2024

I’m really sorry @Xanderwot. We changed our minds about this.

There was some discussion about this feature here https://github.com/orgs/phlex-ruby/discussions/761. We also discovered it added a 16% performance overhead.

I really appreciate your contributions and I’m sorry this one didn’t make it.

@joeldrapper joeldrapper marked this pull request as ready for review September 4, 2024 22:57
@Xanderwot
Copy link
Contributor

👍
I totally understand what its pretty specific and probably rare used feature
Anyway just as discussion possibility:
What do you think about moving this feature under configuration option(like Phlex.config.enable_inline_tags)?
So it will allow to keep performance and make this feature optional.

Thanks for cooperation anyway

@@ -32,21 +32,13 @@ def register_element(method_name, tag: method_name.name.tr("_", "-"))
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
# frozen_string_literal: true

def #{method_name}(content = Phlex::Null, **attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to remove Phlex::Null definition also :)

@joeldrapper
Copy link
Collaborator Author

joeldrapper commented Sep 5, 2024

What do you think about moving this feature under configuration option(like Phlex.config.enable_inline_tags)?

The problem is any kind of check we do in those generated methods can have such a significant impact on the overall performance because they’re hit so many times.

I think there's a way you could patch it though so inline content still works.

As a little proof of concept, you should be able to do something like this

def div(content = nil, *, **)
  if content
    super(*, **) { plain(content) }
  else
    super
  end
end

You could iterate over Phlex::HTML.registered_elements and redefine each one.

@Xanderwot
Copy link
Contributor

The problem is any kind of check we do in those generated methods can have such a significant impact on the overall performance because they’re hit so many times.

Idea was to move check at top level register_element so it will create original #{method_name} method if option disabled. So it will not decrease performance but will increate code lines because it will have two sets of metaprogrammed methods.
Anyway looks like patching is my only option, because rewriting fortitude legacy is to painful and time-consumable :)

@joeldrapper
Copy link
Collaborator Author

I guess we could break up the code generation into small parts that each can be patched. I’m trying to avoid over-complicating things though as that file is already pretty messy.

@joeldrapper joeldrapper merged commit bf82dfc into main Sep 5, 2024
7 of 12 checks passed
@joeldrapper joeldrapper deleted the remove-inline-content branch September 5, 2024 01:07
@joeldrapper joeldrapper restored the remove-inline-content branch September 5, 2024 01:07
@joeldrapper joeldrapper deleted the remove-inline-content branch September 5, 2024 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants