Skip to content

Conversation

@pelme
Copy link
Owner

@pelme pelme commented Sep 17, 2025

A lot of htpy code is static calls that are hard coded in the source
code like p(id="foo"). Every time it is invoked, a Python function call
needs to happen to translate the Python keyword argument id to a HTML attribute string.

With some ast rewrite tricks, we can find all calls to htpy functions
that only have strings/dict literals/literal child nodes etc. We can
then replace them with static strings.

This commit replaces static calls with the resulting string and a CompiledElement.

Doing that would effectively lead htpy code to be almost zero overhead,
close to hand optimized string concatenation.

(This is currently a very rough PoC version)

A lot of htpy code is static calls that are hard coded in the source
code like `p(id="foo")`. Every time it is invoked, a Python function call
needs to happen to translate the Python keyword argument id to a HTML attribute string.

With some ast rewrite tricks, we can find all calls to htpy functions
that only have strings/dict literals/literal child nodes etc. We can
then replace them with static strings.

This commit replaces static calls with the resulting string and a CompiledElement.

Doing that would effectively lead htpy code to be almost zero overhead,
close to hand optimized string concatenation.

(This is currently a very rough PoC version)
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