Skip to content

3.0.0.beta2

Pre-release
Pre-release

Choose a tag to compare

@joeldrapper joeldrapper released this 01 Dec 10:43
2eb4040

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 }
end

This 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 plain are formatted at compile time. Redefining format_object recompiles 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#== or TrueClass#== in Ruby, such as Mongoid apps through bson. It used to refuse every file. (#1115)
  • Compiling no longer autoloads a Set constant in the component's namespace, such as a Zeitwerk Workout::Set model. (#1117)
  • Files with # encoding: binary keep their encoding when compiled. (#1117)
  • Methods defined by class_eval strings are no longer compiled from an unrelated def at the same line. (#1117)
  • Static Float attributes such as 1e3 and 1_0.5 are serialised as numbers rather than their source text. (#1112)
  • Phlex::Compiler.explain reports 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

Full Changelog: 3.0.0.beta1...3.0.0.beta2