<jokke>
the require "./dsl" is nonsense of course. it just was a deperate attempt of making the macro expansion work
<sdogruyol>
this looks interesting
<jokke>
there is one drawback to the current implementation though. If one does the usual get "/foo" do ... end, they cant affekt the name of the context variable passed to the block
<jokke>
*affect
<sdogruyol>
how so?
<jokke>
because macros can't have named block params
<sdogruyol>
i need to take a deeper look at your macro
<sdogruyol>
:)
<jokke>
so they can do get "/foo" do ... end but the name of the context variable will always be context and there's no way to rename it with get "/foo" do |my_context| ... end
<sdogruyol>
i think the thing you build should be firstly compatible with Crystal HTTP and then later Kemal or others
<jokke>
sdogruyol: what i'd really like to see in kemal is being able to transform the return values of the path blocks with filters
<sdogruyol>
can you given an example of that?
<jokke>
yeah
<sdogruyol>
you can modify the context
<jokke>
yeah i know
<jokke>
but the return value of the blocks are to_ssed and passed to context.response.print, right?
<sdogruyol>
yeah correct
<jokke>
there's no way to modify it after that since it's an io
<sdogruyol>
well you can flush and rebuild it as you want
<sdogruyol>
but that’d be expensive to dos
<sdogruyol>
so*
<jokke>
yeah
<sdogruyol>
but it’s a trade-off i guess. If you want that much of flexibility that’s acceptable (or not?)
<jokke>
my point is that it would allow building a lot more powerful middleware if there would be something like BodyHandlers or so that could modify the body and pass it along the chain and at the very end it would be written to the response
<jokke>
even better imho would be a handler that would be passed both the context and the body to it's call method
<sdogruyol>
what if you would want to write something to context in the middle?
<jokke>
yeah that'd be possible
<jokke>
ah you mean to the body?
<sdogruyol>
what if a buffered body existed?
<jokke>
yeah that's a problem
<sdogruyol>
or what if we build all the middlewares as buffered and then call to_s only at the end?
<sdogruyol>
that sounds like a good idea but need to give it a try
<jokke>
what do you mean with buffered?
<jokke>
i think it's only powerful if the content can be any value until the very end
<sdogruyol>
yeah
<sdogruyol>
that means can be anything / can be modified anytime till the very end right?
<jokke>
so, to come back to my json api example, i could write a middleware which would check if the content is a JSONApi::Response, set headers and return codes and serialize the response
<jokke>
yeah
<jokke>
exactly
<sdogruyol>
for Kemal creating a special Handler and making every middleware inherit from that Handler instead of HTTP::Handler would make it possible
<jokke>
yes
<jokke>
and it wouldn't rule out writing normal middleware either
<jokke>
normal meaning HTTP::Handler
<sdogruyol>
well practically we’ll define an interface for others to comply
<jokke>
yes
r00takaspin has joined #crystal-lang
<jokke>
sdogruyol: would you like me to try something regarding this middleware handler?
<sdogruyol>
that’d be interesting
<sdogruyol>
but currently i have no vague idea about how it should be :P
<jokke>
ok, i'll try some things out
<sdogruyol>
great! Thanks :)
<jokke>
np :)
<sdogruyol>
i’ll try jsonapi soon
<jokke>
cool :)
<sdogruyol>
i’ve a pretty huge (and slow) JBuilder template. Which would be a really great use case for this
<sdogruyol>
it takes around 2 secs to render thanks to Rails :P
<jokke>
yeah tell me about it...
<jokke>
we use active model serializers at work...
<Netfeed>
~
<jokke>
it takes _ages_ for any significant amount of data to render
<sdogruyol>
well JBuilder is abysmally slow
<jokke>
haven't heard about JBuilder before
<sdogruyol>
i rendered that with JSON.builder in Crystal
<jokke>
just about rabl and active model serializers
<sdogruyol>
the code was a horror but the speed was like 100x faster
<jokke>
haha
<sdogruyol>
2 sec went down to 20 ms :P
<jokke>
yeah well JSON Api is very specific though.. it's designed to render json conforming to the json api spec..
<sdogruyol>
I’ve tried AMS for the same template and it did increase only %10 so i gave up on the switch
<jokke>
but you might be able to reuse some components
<jokke>
the the caching for example
<sdogruyol>
yeah i know but still that slowness bothers me :(
<jokke>
20ms is pretty good?
<jokke>
depending on the size of the json and complexity of the data of course
<sdogruyol>
Yeah
<jokke>
i'm getting max 200 serializations per second for rendering a roughly 500 KiB JSON of objects with random data
<jokke>
that's the raw throughput without any io
<sdogruyol>
hmm
<sdogruyol>
why is that so slow?
<jokke>
do you think it's slow?
<jokke>
that's 5ms in average
<jokke>
i really doubt that it's the bottleneck. fetching data from the db and actually writing the data to the socket will take much longer in comparison
<jokke>
and that json would be the equivalent of quering 1K rows/documents from a db
<jokke>
Without any caching i'm at 50 serializations per second btw
<jokke>
that'd be your 20ms
<jokke>
but i'd suggest try it out with real world use cases and see what it can do. That's what i'm planning to do in the next couple of days now. I'm writing my bachelor thesis about a system with a caching api and reactive ui.
<jokke>
ui will be a redux app. I must say webpack, es6 and redux makes even javascript bearable :)
<sdogruyol>
jokke: that sounds great
<sdogruyol>
can you show me the json for your serialization benchmark?
<jokke>
heh i never outputted it before. wait a sec
pawnbox has joined #crystal-lang
<jokke>
sdogruyol: would you like me to pretty print it?
<jokke>
i should say that's not possible with the caching. or it kind of is, but may look weird since a cached portion might have wrong indentation
<sdogruyol>
sure
<jokke>
so i'll pass it through ruby -r json -e 'JSON.pretty_generate(JSON.parse(STDIN.read))'
<jokke>
oh i actually get 250 per second
<jokke>
wow i'm pretty impressed about ruby's json libs speed..
<jokke>
because it's hard to predict what kind of data there would be in the "real world'
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 276 seconds]
<jokke>
lol totally wrong numbers.. had a fix coded 1000 in the calculation
<crystal-gh>
[crystal] asterite pushed 3 new commits to master: https://git.io/v2Uuf
<crystal-gh>
crystal/master 883d002 Ary Borenszweig: Stats: show heap memory
<crystal-gh>
crystal/master 5c412ae Ary Borenszweig: Merge branch 'master' of github.com:manastech/crystal
<crystal-gh>
crystal/master fb999c9 Ary Borenszweig: Improve error message when assigning an incorrect type to an instance variable with a declared ttype
<travis-ci>
manastech/crystal#fb999c9 (master - Improve error message when assigning an incorrect type to an instance variable with a declared ttype): The build passed. https://travis-ci.org/manastech/crystal/builds/110507771
r00takaspin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]