vapor / template-kit

📄 Easy-to-use foundation for building powerful templating languages in Swift.
MIT License
46 stars 17 forks source link

Conform `Data` to `TemplateDataRepresentable` by encoding it has a hex-encoded string #47

Closed MrMage closed 5 years ago

MrMage commented 5 years ago

Motivation: encoding large arrays of primitive types as TemplateData is fairly slow. The default encoding strategy for Data is to encode it as an array of bytes, which falls victim to that.

This PR avoids an accidental slowdown for the case where a model contains a Data field that gets encoded by default by the TemplateDataEncoder. (In one case, this change has reduced render times on a large page from ~3.75s to ~460ms in a Release build.)

In addition, encoding Data as a hex-encoded string arguably makes more sense than encoding it as an array of integers.

MrMage commented 5 years ago

This has been superseded by https://github.com/vapor/template-kit/pull/50.