-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native pascal code for templates #144
Comments
I've done a small proof of concept so far. There may be some guidelines to how to write templates that can be native code. Further, my approach allows for native code to co-exist with interpreted code. e.g.
Code generator on a template:
creates code the code:
All that is required is to include the unit in the project. The unit injects the native template into the template registry, so transitioning from having interpreted code to having native code is 'right click - add unit' once the code generation step is done. Ok - setting up code generation currently requires a little bit of work, but again something I hope can be automated. The nice thing in the above, the code generator uses the information from the <% requires 'Model.TIndex' %> to identify the TIndex record and then binds natively onto the parameters, without needing RTTI. Unit references to types would be automatically included. There is still a little RTTI in terms of the TValue, but it is just a container for the data payload. Benchmark results:
That is almost 14 times faster! We sort of expect that, but nice to see the improvement of a simple for loop using native code vs interpreted code using RTTI. |
Been experimenting with LLVM. Possibly, we just use the LLVM JIT. |
The template engine is currently based off a parser and interpreter. This is pretty useful for many purposes especially where dynamic interpretation requirements exist. However, templates can take time to evaluate by the interpreter depending on the logic, even if it is in the order of ms, it is still suboptimal.
Once an app and templates are mature/ ready for release, some circumstances will allow for templates to be fixed. The benefit of the design, is that most of the template language constructs map onto Delphi language constructs. We can introduce a pre-processor code generation step that emits code that can be registered with the TTemplateRegistry, allowing for native compiled speed when it comes to output being generated. Even then, there can still be a fallback to interpretation if required.
This may have some implications:
comment below if interested. This may be available only to commercial supporters.
The text was updated successfully, but these errors were encountered: