Skip to content
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

Too much #eval of strings #6

Open
ferrous26 opened this issue May 31, 2011 · 12 comments
Open

Too much #eval of strings #6

ferrous26 opened this issue May 31, 2011 · 12 comments

Comments

@ferrous26
Copy link
Member

There is entirely too much use of #eval (and close family) of strings in HotCocoa, which leaks memory in MacRuby and is slower than alternatives. In some cases it is inappropriate given the meta-programming hooks available in Ruby 1.9, in other cases we can refactor to get rid of it.

hotcocoa/delegate_builder.rb
57:    eval %{

hotcocoa/graphics/canvas.rb
145:          send(:instance_eval, &block)

hotcocoa/graphics/color.rb
200:      metaclass.instance_eval do

hotcocoa/graphics/path.rb
54:          self.send(:instance_eval, &block)

hotcocoa/kvo_accessors.rb
29:    c.module_eval &b

hotcocoa/mapper.rb
59:    mod.module_eval(&block)
179:          delegate_module.module_eval <<-EOM
189:        delegate_module.module_eval <<-EOM
220:      bindings_module.module_eval <<-EOM

hotcocoa/mapping_methods.rb
107:      @custom_methods.module_eval(&block)

hotcocoa/mappings/appkit/color.rb
4:      color = eval("NSColor.#{options.delete(:name)}Color")

hotcocoa/mappings/appkit/font.rb
34:        font = eval("NSFont.#{method}(#{options.delete(key)})")

hotcocoa/mvc.rb
140:    HotCocoaController.class_eval %{
@ferrous26
Copy link
Member Author

Took care of lib/hotcocoa/mapper.rb:220

@ferrous26
Copy link
Member Author

Took care of hotcocoa/mappings/appkit/color.rb:4

@ferrous26
Copy link
Member Author

Took care of hotcocoa/mappings/appkit/font.rb:34

@ferrous26
Copy link
Member Author

I think for hotcocoa/delegate_builder.rb:57 we can only make the code inside of eval smaller, but because of the delegation mechanics we cannot completely remove it.

@ferrous26
Copy link
Member Author

Took care of hotcocoa/mapping_methods:107

@isaac
Copy link

isaac commented Jul 17, 2011

Hey, I'm curious if you're OK with methods like Module#define_method which can use module_eval under the covers. Or is it just evaling strings that you want to minimize in HotCocoa?

@ferrous26
Copy link
Member Author

@isaac yes, it is the eval'ing of strings that I want to minimize, Module#define_method is, I think, the suitable replacement in most cases, especially where #module_eval is being called just to define a method.

@ferrous26
Copy link
Member Author

I've adjusted the bug to better reflect what I meant. Thanks for pointing that out, @isaac

@ferrous26
Copy link
Member Author

mapper.rb:59 is not changeable

@ferrous26
Copy link
Member Author

mapper.rb:179 and mapper.rb:189 are now taken care of

mapper.rb:179 has an odd looking solution, it is a workaround to a small issue I was having with MacRuby, not sure if it is a MacRuby bug or not

@ferrous26
Copy link
Member Author

The only cases left are:

delegate_builder.rb:57

This one is kind of important since it is used by every delegate that is set up using Hot Cocoa style delegation. Though, we can only reduce the amount of code that needs to be evaluated as a string.

mvc.rb:140

Not too big a deal right now. I haven't even gotten around to really looking at the file yet and it has to be explicitly loaded. No examples use this, and it had a syntax issue that was not discovered until we tried compiling the file.

@ferrous26
Copy link
Member Author

The reason for the workaround has been discovered to be a MacRuby bug. See MacRuby Ticket #1371.

@ghost ghost assigned ferrous26 Aug 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants