You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L199
I believe textOnly = tag.textOnly or not bool(len(tag.block.nodes)) could be replaced by textOnly = tag.textOnly or not tag.block.nodes. The truthy value of a container is already False if it's empty, True otherwise. But maybe I've missed something.
About format_path ( https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L273 ):
Checking if a character is in a string (especially one that is likely to be at the end of the string) may be slightly costly. Well, it's not that costly, but for extension, we have a function made for that job: os.path.splitext.
I've created the following snippet. I encourage you to run it on your own system.
Hi,
Just checking this "High Performance" port, I noticed a few things:
inlineTags
( https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L18 )selfClosing
( https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L40 )autocloseCode
( https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L51 )should be sets and not lists.
We seem to only do lookups. This costs O(n) and a set would make it O(1).
Replacing
[...]
by{...}
would make the change. I haven't checked, but if they're constants, then, we should replace[...]
byfrozenset([...])
instead.As
autocloseCode
can mutate, it should be aset
and the register method would become:In https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L199
I believe
textOnly = tag.textOnly or not bool(len(tag.block.nodes))
could be replaced bytextOnly = tag.textOnly or not tag.block.nodes
. The truthy value of a container is alreadyFalse
if it's empty,True
otherwise. But maybe I've missed something.About format_path ( https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L273 ):
Checking if a character is in a string (especially one that is likely to be at the end of the string) may be slightly costly. Well, it's not that costly, but for extension, we have a function made for that job:
os.path.splitext
.I've created the following snippet. I encourage you to run it on your own system.
It's a 25-30% performance gain.
In https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L296
TYPE_CODE
is a constant and should be declared outside of the function (to avoid recreating it for every function call).Another place about set/list:
https://github.com/syrusakbary/pyjade/blob/master/pyjade/compiler.py#L307
What does it mean?
set
will always be faster than alist
to lookup. Especially if there are non-matching candidates.set
always costs the same.set
is more costly to build than alist
.set
becomes cheaper again.Here again, we can expect up to 17% performance improvement (if there are many misses).
That's pretty much it, in terms of what pops to the eyes, in
compiler.py
.Keep up the good work!
The text was updated successfully, but these errors were encountered: