-
Notifications
You must be signed in to change notification settings - Fork 132
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
Shouldn't DSL functions be inline? #67
Comments
Originally it was planned to have them inline however it was inefficient in old kotlin-js compilers. Need to be investigated again |
+1 Not just because of anonymous classes/runtime performance, but making them inline would enable suspend calls inside the DSL which is not possible right now. So it is not prohibitive for the JS Backend now, it would be a really nice improvement :) |
While writing DOM — may be. While streaming (on JVM) — no! First fetch data, next return HTML, |
I agree with @Miha-x64 on data first. However, making it all inline might explode the size of bytecode generated. If it could be an option… |
I see your point on data first, and makes sense. Now let me explain to you a use case based on my experience and with a example/rationale behind it. Suppose I'm creating a CMS, or a plain website. That website has pieces that I can put in different places Now consider the following reusable piece of code:
Where cache block is just computed on cache-miss based on a key, and computes a plain string without having to generate objects per each tag for each requesst, You can always compute what is required and what is not before html rendering. But you have to do that explicitly while here it is just natural. Obviously this is just an idea. I have been coding a lot of years in PHP, and maybe this approach has too many flaws. But wanted to share anyway so you can consider it :) In a plain MVC the controller usually grabs data and passes it to the view. But sometimes, you just compute more data than required, and that doesn't allow to compute it lazily. I worked for a big PHP company a lot of years ago and I have seen it. At least, they, computed more than required. Also since some people worked on views and other in controllers, that was pretty common. Some years later I tried an approach where views were the ones that lazily requested what it needs. I did this https://github.com/soywiz/atpl.js and created a couple of sites with that approach. |
Sorry if I am being dense but what is the bytecode size difference of inlining the code? Isnt it only these functions that need to be inlined?
I havent performed any tests but intuitively that doesnt seem like much. Especially when taking into account the overhead of all those class files. |
I performed a quick test with the test classes in module kotlinx-html-jvm.
I added inline modifiers to
Unless I have made a mistake or we need to count size some other way then it seems like a pretty nice win. |
I've recently stumbled upon the need for inline DSL functions, too, while trying to naively invoke a suspending function |
If the inline DLS functions delegate most of their implementation to non inline functions as to have minimum inline code apart from the passed lambda, the bytecode size might not explode that much, and could even shrink as inline generates less classes and methods. |
What are the outstanding issues to making a decision on this ? |
Is it necessary to have an anonymous class per DSL lambda?
The text was updated successfully, but these errors were encountered: