Repository navigation
3.0.0.beta2
Pre-release
Pre-release
Highlights
The second beta of Phlex 3. It makes the C attribute serialiser faster, lets the compiler inline more of your templates, and fixes several cases where compiling changed behaviour. There are no breaking changes since beta1.
Faster C attribute serialiser
The optional C extension serialises attributes 1.2 to 2.6 times faster, with byte-identical output. Whole pages render up to 1.39 times faster without the compiler and up to 1.28 times faster with it. (#1118)
- Attribute values are scanned for characters that need escaping in one pass, 16 bytes at a time with SSE2 or NEON, or 8 bytes elsewhere.
- Output is marked as 7-bit when its input was, so appending it to the buffer doesn't scan it again.
- Attribute names given as static Symbols are cached after their first check, without taking Ruby's global symbol lock.
The compiler inlines constants, literal locals and numbers
LABEL = "Save"
def view_template
count = 3
div { LABEL }
div { count }
div { 42 }
endThis now compiles to a single static append, behind a guard that checks LABEL and count still hold the same objects. If they don't, the code runs as it would uncompiled. In our benchmarks templates like this rendered about twice as fast. (#1112)
- A local is inlined when the method assigns it a symbol,
nil, a small integer, a float or a frozen string exactly once. - A constant is inlined when it holds one of those at compile time. Compiling never autoloads a constant or calls
const_missing. - Numbers returned from an element's block or given to
plainare formatted at compile time. Redefiningformat_objectrecompiles the component. - One new documented difference: if reading the constant raises (for example, it was removed) or runs code (autoload,
const_missing), output just before it in the same run of static HTML hasn't been appended yet.
Fixes
- The compiler works in apps that define
NilClass#==orTrueClass#==in Ruby, such as Mongoid apps through bson. It used to refuse every file. (#1115) - Compiling no longer autoloads a
Setconstant in the component's namespace, such as a ZeitwerkWorkout::Setmodel. (#1117) - Files with
# encoding: binarykeep their encoding when compiled. (#1117) - Methods defined by
class_evalstrings are no longer compiled from an unrelateddefat the same line. (#1117) - Static Float attributes such as
1e3and1_0.5are serialised as numbers rather than their source text. (#1112) Phlex::Compiler.explainreports only the calls actually left uncompiled past the block depth limit, rather than reporting a whole block that may have compiled. (#1110)- The documented differences now list what tooling sees generated source:
caller,caller_locations, line coverage, breakpoints and TracePoint. (#1117)
What's Changed
- Report only the calls left uncompiled past the block depth limit by @joeldrapper in #1110
- Inline constants and literal locals behind identity guards by @joeldrapper in #1112
- Strengthen tests with mutation testing by @joeldrapper in #1113
- Compile in apps that define NilClass#== in Ruby, such as with bson by @joeldrapper in #1115
- Fix three compiler edge cases and document tooling differences by @joeldrapper in #1117
- Speed up the C attribute serializer by @joeldrapper in #1118
- Bump version to 3.0.0.beta2 by @joeldrapper in #1119
Full Changelog: 3.0.0.beta1...3.0.0.beta2