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

Speedup of the Cappuccino framework by more efficient objj_msgSend #2384

Merged
merged 7 commits into from Nov 1, 2015

Conversation

mrcarlberg
Copy link
Member

This pull request will make Objective-J run faster by implementing a more efficient objj_msgSend function and objj_method implementation. The compiler can also optionally inline the function to increase the speed even more.

Initial tests show that the speed increase is more than 50% in special cases. For a general Objective-J application the speed increase is around 20%.

The speed increase is possible by the following improvements:

  1. More efficient objj_method implemention. That bad thing here is that the name property on objj_method has to change to method_name.
  2. objj_msgSend and objj_msgSendSuper functions has a more efficient implementation.
  3. Array and Dictionary Literals generate more efficient code.
  4. The objj_msgSend and objj_msgSendSuper functions are optionally inlined by the compiler.

How to use:

• The Release version of the Cappuccino framework will have inlined objj_msgSend and objj_msgSendSuper functions. The Debugversion will use the old obj_msgSend functions.
• To generate inlined code when compiling in the browser add the below line in the index[-debug].html file.

OBJJ_COMPILER_FLAGS = ["IncludeDebugSymbols", "IncludeTypeSignatures", "InlineMsgSend"];

• To generate inline code for the Release version of your project when building from command line change task.setCompilerFlags("-O"); to task.setCompilerFlags("-O2"); in the project Jakefile. This is needed for all your subprojects and frameworks too.

A new version of OJTest framework (https://github.com/cappuccino/OJTest) is needed to run the test cases. Copy it to the package folder in the Narwhal directory.

…ions. More efficient implementation of objj_method.
…o framework with objj_msgSend function inlined. Also introduced options in ’index-debug.html’ templates to allow inline of objj_msgSend function when compiling in browser.
@cappbot cappbot added this to the Someday milestone Oct 6, 2015
@cappbot cappbot added the #new label Oct 6, 2015
@cappbot
Copy link

cappbot commented Oct 6, 2015

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

@aljungberg
Copy link
Member

The objj_msgSend and objj_msgSendSuper functions are optionally inlined by the compiler.

How does that handle method swizzling?

@mrcarlberg
Copy link
Member Author

The same code is just inlined so it works fine.
The thing you can't do is use decorators on obj_msgSend.
The compiler will only optionally inline the functions on the release version when building from command line.

@aljungberg
Copy link
Member

Ah I get it. Yeah the most common objj_msgSend decorators are all about debugging so enabling this option for release code makes sense.

Shouldn't this PR have some code generation unit tests?

@mrcarlberg
Copy link
Member Author

Yes, it definitively needs some code generation unit tests. I have plans to do the OutputTest in two different versions, one standard and one inlined. But I will add those when I know that the new code works for everyone.

@boucher
Copy link
Member

boucher commented Oct 6, 2015

Very cool!

On Tue, Oct 6, 2015 at 6:39 AM Martin Carlberg notifications@github.com
wrote:

Yes, it definitively needs some code generation unit tests. I have plans
to do the OutputTest in two different versions, one standard and one
inlined. But I will add those when I know that the new code works for
everyone.


Reply to this email directly or view it on GitHub
#2384 (comment)
.

@primalmotion
Copy link
Member

That doesn't work on our built application either in release, release+press or release+press+flatten

The page just hangs. If I make the browser to stop on all exceptions I get an exception, but no message is logged anywhere

screen shot 2015-10-06 at 10 40 01

@primalmotion
Copy link
Member

edit: in release, it doesn't load, but actually logs an exception:

TypeError: undefined is not an object (evaluating 'CPDictionary.isa.method_msgSend')

@mrcarlberg
Copy link
Member Author

Hmm, this is strange. Are you sure it is running against a new Objective-J Runtime?

It feels like you are running on an old Runtime as it gets undefined when evaluating CPDictionary.isa.method_msgSend All objj_classobjects should have the attribute method_msgSend

@primalmotion
Copy link
Member

my bad actually :)

I did not realize I had to activate the -O2 flag for all libraries

It's working great, we'll do some testing and report any issue.

Great Job!

@cappbot
Copy link

cappbot commented Oct 6, 2015

Milestone: Someday. Labels: #accepted, #needs-unit-test, Objective-J. What's next? This issue needs a volunteer to write and submit one or more unit tests execercising the changes and/or the relevant parts of the original problem.

@mrcarlberg
Copy link
Member Author

I have now added code generation unit test cases with inlined objj_msgSend functions for all tests in OutputTest

@cappbot
Copy link

cappbot commented Oct 7, 2015

Milestone: Someday. Labels: #accepted, Objective-J. What's next? A reviewer should examine this issue.

@cappbot
Copy link

cappbot commented Oct 8, 2015

Milestone: Someday. Labels: #accepted, Objective-J. What's next? A reviewer should examine this issue.

… so compiler flags can be set after the files are compiled. This implementation works all the time.
@mrcarlberg
Copy link
Member Author

I have now fixed a problem with compiler flags when compiling in the browser.

@mrcarlberg
Copy link
Member Author

I don't have any more outstanding issues. We are now using it in our project and are happy with it.

@aljungberg
Copy link
Member

Looks good so far. Some minor points we should be aware of:

  • larger build output since each message send is more code
  • _objj_forward becomes a keyword
  • uses (very slightly) more memory to add method_msgSend to the isas after class initialisation

Did you compare the size of your build output for your app with and without this? What about memory usage in the browser? If it's 20-50% faster I imagine it can't be too significant.

@mrcarlberg
Copy link
Member Author

The code size does increase:
Foundationgoes from 987,634 bytes to 1,151,583 bytes. (+17%)
AppKitgoes from 3,587,337 bytes to 4,343,767 bytes. (+21%)
This is not compressed and not zipped.

I can't see any difference in memory usage in the Browser but as you say it should be a small increase.

Removed the ’release-inline’ option when building as it is not practical to have two different options. The release build now always has inlined msgSend functions. If a release build is needed without inlined msgSend functions an edit of the ”-O2” option to ”-O” in the Jakefile is needed.
@@ -45,6 +45,23 @@ if (DOMBaseElementsCount > 0)
pageURL = new CFURL(DOMBaseElementHref, pageURL);
}

// Set compiler flags

if (OBJJ_COMPILER_FLAGS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates a Uncaught ReferenceError: OBJJ_COMPILER_FLAGS is not defined on Chrome.

typeof OBJJ_COMPILER_FLAGS !== 'undefined'

would be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this problem. I'll make a fix for this.

@Dogild
Copy link
Member

Dogild commented Nov 1, 2015

Are we good with this one @mrcarlberg ?

@cappbot
Copy link

cappbot commented Nov 1, 2015

Assignee: mrcarlberg. Milestone: Someday. Labels: #works-for-me, Objective-J. What's next? Attempts to reproduce the problem described by this issue have failed to reveal any erroneous situation.

mrcarlberg added a commit that referenced this pull request Nov 1, 2015
Speedup of the Cappuccino framework by more efficient objj_msgSend
@mrcarlberg mrcarlberg merged commit 8c2f0ba into cappuccino:master Nov 1, 2015
@mrcarlberg mrcarlberg deleted the even_faster_objj_msg_send branch February 5, 2016 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants