-
Notifications
You must be signed in to change notification settings - Fork 1
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
[WIP] Codegen draft #21
Closed
Closed
+593
−73
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
antoinedc
force-pushed
the
codegenfailed
branch
4 times, most recently
from
July 23, 2017 17:17
4dfb7f4
to
a125289
Compare
Example on this BABL template {
list: pin(:size) { |size|
each.object(
id: _.integer,
static_val: { a: 1 },
blabla: _.nullable.object(:status),
outer_list_size: size,
prop4: _,
nested: _.each.nav(:sub).object(
prop1: _.string,
prop2: _.nullable.number,
prop3: _.boolean,
prop4: _,
prop5: _,
prop6: _,
parent_id: [parent.parent.parent.nav(:id)]
)
)
}
} def x156(v0)
{:list => (x0(v0,(R0)).map { |l0| ({:id => (begin; l1 = x1((R1),((l0)),(:id)); ((::Integer === ((l1)) ? ((l1)) : (Babl::Nodes::Shared::ErrorHandling.raise_message(
'Expected type integer:' + ((l1)).inspect, (R1)
)
))); end),
:static_val => ({:a => (1)}),
:blabla => (begin; l2 = x1((R2),((l0)),(:blabla)); ((( l4 = x15((R6),((l2)),(R5),(l2))
x14((l4))
))?((nil)):(((true))?(({:status => (begin; l3 = x1((R4),((l2)),(:status)); (x10(((l3)),(R4))); end)})):((raise Errors::RenderingError, R3
)))); end),
:outer_list_size => (begin; l5 = x1((R7),(v0),(:size)); (x10(((l5)),(R7))); end),
:prop4 => (begin; l6 = x1((R8),((l0)),(:prop4)); (x10(((l6)),(R8))); end),
:nested => (begin; l7 = x1((R9),((l0)),(:nested)); (x0((l7),(R9)).map { |l8| (begin; l9 = x1((R10),((l8)),(:sub)); ({:prop1 => (begin; l10 = x1((R11),((l9)),(:prop1)); ((::String === ((l10)) ? ((l10)) : (Babl::Nodes::Shared::ErrorHandling.raise_message(
'Expected type string:' + ((l10)).inspect, (R11)
)
))); end),
:prop2 => (begin; l11 = x1((R12),((l9)),(:prop2)); ((( l12 = x15((R13),((l11)),(R5),(l11))
x14((l12))
))?((nil)):(((true))?(((::Numeric === ((l11)) ? ((l11)) : (Babl::Nodes::Shared::ErrorHandling.raise_message(
'Expected type number:' + ((l11)).inspect, (R12)
)
)))):((raise Errors::RenderingError, R3
)))); end),
:prop3 => (begin; l13 = x1((R14),((l9)),(:prop3)); ((::TrueClass === ((l13))||::FalseClass === ((l13)) ? ((l13)) : (Babl::Nodes::Shared::ErrorHandling.raise_message(
'Expected type boolean:' + ((l13)).inspect, (R14)
)
))); end),
:prop4 => (begin; l14 = x1((R15),((l9)),(:prop4)); (x10(((l14)),(R15))); end),
:prop5 => (begin; l15 = x1((R16),((l9)),(:prop5)); (x10(((l15)),(R16))); end),
:prop6 => (begin; l16 = x1((R17),((l9)),(:prop6)); (x10(((l16)),(R17))); end),
:parent_id => ([(begin; l17 = x1((R1),((l0)),(:id)); (x10(((l17)),(R1))); end)])}); end) }); end)}) })}
end
def x0(v0,v1)
unless ::Enumerable === v0
Babl::Nodes::Shared::ErrorHandling.raise_message(
'Not enumerable : ' + v0.inspect + "\n",
v1
)
end
v0
end
def x1(v0,v1,v2)
begin
::Hash === v1 ? v1.fetch(v2) : v1.__send__(v2)
rescue ::StandardError => e
Babl::Nodes::Shared::ErrorHandling.raise_enriched(e, v0)
end
end
def x10(v0,v1)
begin
Babl::Nodes::TerminalValue.instance.render_object(v0)
rescue ::Babl::Nodes::TerminalValue::TerminalValueError => e
Babl::Nodes::Shared::ErrorHandling.raise_enriched(e, v1 + e.babl_stack)
end
end
def x15(v0,v1,v2,v3)
begin
v2.call(x14(v3))
rescue ::StandardError => e
Babl::Nodes::Shared::ErrorHandling.raise_enriched(e, v0)
end
end
def x14(v0)
v0
end
def evaluate(v0)
x156(v0)
end
R0 = []
R1 = [:"#", :id]
R2 = [:"#", :blabla]
R3 = "A least one switch() condition must be taken"
R4 = [:"#", :blabla, :status]
R5 = #<Proc:0x007f97d288eb88(&:nil?)>
R6 = [:"#", :blabla, :__block__]
R7 = [:size]
R8 = [:"#", :prop4]
R9 = [:"#", :nested]
R10 = [:"#", :nested, :"#", :sub]
R11 = [:"#", :nested, :"#", :sub, :prop1]
R12 = [:"#", :nested, :"#", :sub, :prop2]
R13 = [:"#", :nested, :"#", :sub, :prop2, :__block__]
R14 = [:"#", :nested, :"#", :sub, :prop3]
R15 = [:"#", :nested, :"#", :sub, :prop4]
R16 = [:"#", :nested, :"#", :sub, :prop5]
R17 = [:"#", :nested, :"#", :sub, :prop6] |
antoinedc
force-pushed
the
codegenfailed
branch
5 times, most recently
from
August 7, 2017 21:18
2a4824b
to
02cac56
Compare
antoinedc
force-pushed
the
codegenfailed
branch
3 times, most recently
from
August 13, 2017 16:05
fa4bd60
to
ab59d4f
Compare
antoinedc
force-pushed
the
codegenfailed
branch
from
August 21, 2017 10:37
ab59d4f
to
b05676b
Compare
fterrazzoni
force-pushed
the
codegenfailed
branch
from
September 2, 2017 13:09
b05676b
to
c63d338
Compare
fterrazzoni
force-pushed
the
codegenfailed
branch
2 times, most recently
from
September 3, 2017 12:41
4b5d434
to
8505041
Compare
fterrazzoni
force-pushed
the
codegenfailed
branch
from
September 5, 2017 16:35
8505041
to
78032af
Compare
fterrazzoni
force-pushed
the
codegenfailed
branch
2 times, most recently
from
September 22, 2017 23:24
5c3893d
to
1f98936
Compare
fterrazzoni
force-pushed
the
codegenfailed
branch
from
September 24, 2017 22:02
1f98936
to
a3a03b1
Compare
Close: current rendering time is acceptable and BABL performs very well compared to the alternatives (RABL, etc). Efforts should be put on making compilation faster. Complex templates are pretty slow to compile today. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work in progress / broken / hardcore code quality
BABL does not try to be efficient today, whereas its static structure makes it possible to do much better. Also, BABL is not really GC-friendly, because it tends to generate many temporary objects during rendering. For instance, a new
Babl::Rendering::Context
is instantiated every time a property is accessed.This PR is an attempt to improve performances. It does so by generating Ruby code on the fly during the compilation of the BABL template. The generated Ruby class contains everything needed, which means that the
Node
tree can be GC-ed after that.Design goals are to :
Benchmark :
Branch : master (2017-08-21)
Branch: codegenfailed (2017-08-21)
Run time and the number of allocations is divided by 4.
Current status :