-
Notifications
You must be signed in to change notification settings - Fork 509
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
Basic project configuration engine #1909
Conversation
OpenStruct is much slower than Struct, i've seen lots of benchmarks, and seen some gems that provide a similar interface for a Hash and are faster than OpenStruct. Just some thoughts, |
Thank you for your concern, it's always pleasant to see people care about speed. I modified one of the benchmarks you are talking about to test out configuration use case. As you can see, the problem is not very drastic if you don't create OpenStructs from hash in a loop.
|
What you're mostly testing is read time, a struct would mostly benefit from initialization time, a benchmark like this: require 'benchmark'
require 'ostruct'
REP = 200000
User = Struct.new(:name, :age)
Benchmark.bm 20 do |x|
x.report 'OpenStruct initialization' do
REP.times do
o = OpenStruct.new
20.times do |index|
o[index.to_s.to_sym] = "test"
end
end
end
x.report 'Struct initialization' do
names = 20.times.collect{|i| i.to_s.to_sym}
Tester = Struct.new(*names)
REP.times do
s = Tester.new
20.times do |index|
s[index.to_s.to_sym] = "test"
end
end
end
end Gives this results:
Which shows that an OpenStruct is 10 times slower at initializing a 20 keys, also, from your tests reads take 3 times more from an OpenStruct. But of course to be able to use a Struct you have to know all keys beforehand 😄 Cheers! 🍻 |
I'm not arguing on OpenStruct speed. I'm showing you a benchmark of the use case of Padrino configuration. Do you actually think Padrino project would initialize tons of it's configuration keys? |
@ujifgc of course not, maybe i didn't express myself correctly, i don't think using any OpenStruct would make such a big difference, i don't believe tons of configuration keys will be written or read. |
I fail to see any reason to not use OpenStruct. I think it's very convenient and easy. Using Struct would limit the usage of configuration storage and provide no real benefits. |
Might be a stupid questions but how does this differ from sinatra's configuration itself: http://www.sinatrarb.com/intro.html#Configuration itself? is the primary difference the assignment syntax? |
Sinatra configuration is application-specific. This PR allows to configure your project and potentially Padrino modules. |
Why did you close this PR? This essence seems reasonable, though the configuration style can be discussed. |
I came to conclusion that it's lame and can be avoided. Reopened for discussion. |
Looks good. |
Basic project configuration engine
ref #1832
I retracted from the idea of configuring Padrino modules by calling their fields as it would overly complicate the implementation and repeat the existing fine gems like https://github.com/beatrichartz/configurations and https://github.com/markbates/configatron.
The configuration now only supports very basic OpenStruct syntax with an environment filter. Just Ruby, no magic, no DSL:
I think this implementation covers the basic needs of configuring a project while not bloating it and leaving space for more comprehensive solutions.