#420: Add ability to optimize function calls with lambda in function position. Use it to optimize jss --------------------------+---------------------------- Reporter: mevenson | Owner: Type: enhancement | Status: new Priority: major | Milestone: 1.5.0 Component: compiler | Version: 1.5.0-dev Keywords: github-issue | Parent Tickets: --------------------------+---------------------------- Precompiler: When compiling a form with a lambda in the function position, possibly optimize it
Case 1: If the lambda has a single form in it, let someone define a transform using:
define-function-position-lambda-transform (body-function-name (arglist form args) &body body)
body-function-name is the car of the single form in the lambda arglist is the arglist of the lambda form is the single form within the lambda args are the arguments to which the lambda will be defined.
The function should check whether it can do a transform, and do it if so, otherwise return nil signalling it couldn't
Case 2: If case 1 is not successful then if the arglist is a simple one (no &key, &rest, &optional) then do a standard beta-reduction binding the args to arglist using let (https://wiki.haskell.org/Beta_reduction)
If not, return and do the usual thing.
An example is in contrib/jss/optimize-java-call.lisp
To see benefits, (compile-file contrib/jss/test-optimize-java-call.lisp) and then load the compiled file. You should see something like the below which reports the timings for the optimized and unoptimized version of 10000 calls of (#"compile" 'regex.pattern ".*")
--
With optimization: (INVOKE-RESTARGS-MACRO "compile" (QUOTE REGEX.PATTERN) (LIST ".") NIL T) Without optimization: ((LAMBDA (#:G85648 &REST #:G85649) (INVOKE-RESTARGS "compile" #:G85648 #:G85649 NIL)) (QUOTE REGEX.PATTERN) ".")
JUST-LOOP 0.0 seconds real time 0 cons cells
OPTIMIZED-JSS 0.011 seconds real time 0 cons cells
UNOPTIMIZED-JSS 0.325 seconds real time 800156 cons cells
See: https://mailman.common-lisp.net/pipermail/armedbear- devel/2016-October/003726.html https://mailman.common-lisp.net/pipermail/armedbear- devel/2016-November/003733.html
-- Ticket URL: http://abcl.org/trac/ticket/420 armedbear http://abcl.org armedbear
#420: Add ability to optimize function calls with lambda in function position. Use it to optimize jss ------------------------------+-------------------------- Reporter: mevenson | Owner: Type: enhancement | Status: new Priority: major | Milestone: 1.5.0 Component: compiler | Version: 1.5.0-dev Resolution: | Keywords: github-issue Parent Tickets: | ------------------------------+-------------------------- Description changed by mevenson:
Old description:
Precompiler: When compiling a form with a lambda in the function position, possibly optimize it
Case 1: If the lambda has a single form in it, let someone define a transform using:
define-function-position-lambda-transform (body-function-name (arglist form args) &body body)
body-function-name is the car of the single form in the lambda arglist is the arglist of the lambda form is the single form within the lambda args are the arguments to which the lambda will be defined.
The function should check whether it can do a transform, and do it if so, otherwise return nil signalling it couldn't
Case 2: If case 1 is not successful then if the arglist is a simple one (no &key, &rest, &optional) then do a standard beta-reduction binding the args to arglist using let (https://wiki.haskell.org/Beta_reduction)
If not, return and do the usual thing.
An example is in contrib/jss/optimize-java-call.lisp
To see benefits, (compile-file contrib/jss/test-optimize-java-call.lisp) and then load the compiled file. You should see something like the below which reports the timings for the optimized and unoptimized version of 10000 calls of (#"compile" 'regex.pattern ".*")
--
With optimization: (INVOKE-RESTARGS-MACRO "compile" (QUOTE REGEX.PATTERN) (LIST ".") NIL T) Without optimization: ((LAMBDA (#:G85648 &REST #:G85649) (INVOKE-RESTARGS "compile" #:G85648 #:G85649 NIL)) (QUOTE REGEX.PATTERN) ".")
JUST-LOOP 0.0 seconds real time 0 cons cells
OPTIMIZED-JSS 0.011 seconds real time 0 cons cells
UNOPTIMIZED-JSS 0.325 seconds real time 800156 cons cells
See: https://mailman.common-lisp.net/pipermail/armedbear- devel/2016-October/003726.html https://mailman.common-lisp.net/pipermail/armedbear- devel/2016-November/003733.html
New description:
Alan requests in https://github.com/armedbear/abcl/pull/11:
Precompiler: When compiling a form with a lambda in the function position, possibly optimize it
Case 1: If the lambda has a single form in it, let someone define a transform using:
define-function-position-lambda-transform (body-function-name (arglist form args) &body body)
body-function-name is the car of the single form in the lambda arglist is the arglist of the lambda form is the single form within the lambda args are the arguments to which the lambda will be defined.
The function should check whether it can do a transform, and do it if so, otherwise return nil signalling it couldn't
Case 2: If case 1 is not successful then if the arglist is a simple one (no &key, &rest, &optional) then do a standard beta-reduction binding the args to arglist using let (https://wiki.haskell.org/Beta_reduction)
If not, return and do the usual thing.
An example is in contrib/jss/optimize-java-call.lisp
To see benefits, (compile-file contrib/jss/test-optimize-java-call.lisp) and then load the compiled file. You should see something like the below which reports the timings for the optimized and unoptimized version of 10000 calls of (#"compile" 'regex.pattern ".*")
--
With optimization: (INVOKE-RESTARGS-MACRO "compile" (QUOTE REGEX.PATTERN) (LIST ".") NIL T) Without optimization: ((LAMBDA (#:G85648 &REST #:G85649) (INVOKE-RESTARGS "compile" #:G85648 #:G85649 NIL)) (QUOTE REGEX.PATTERN) ".")
JUST-LOOP 0.0 seconds real time 0 cons cells
OPTIMIZED-JSS 0.011 seconds real time 0 cons cells
UNOPTIMIZED-JSS 0.325 seconds real time 800156 cons cells
See: https://mailman.common-lisp.net/pipermail/armedbear- devel/2016-October/003726.html https://mailman.common-lisp.net/pipermail/armedbear- devel/2016-November/003733.html
--
-- Ticket URL: http://abcl.org/trac/ticket/420#comment:1 armedbear http://abcl.org armedbear
#420: Add ability to optimize function calls with lambda in function position. Use it to optimize jss ------------------------------+-------------------------- Reporter: mevenson | Owner: Type: enhancement | Status: new Priority: major | Milestone: 1.5.0 Component: compiler | Version: 1.5.0-dev Resolution: | Keywords: github-issue Parent Tickets: | ------------------------------+--------------------------
Comment (by mevenson):
Unfortunately there are two side effects with Alan's work:
1) With *INHIBIT-JSS-OPTIMIZATION* as nil, JSS won't compile any reference to a Java class that it not present in the classpath at compile time. Previously this wasn't the behavior
2) There are a slew of additional failures in the ANSI-TEST LAMBDA section, which indicates that we need to work through some wrinkles in the behavior of the patch.
{{{ LAMBDA.1, LAMBDA.2, LAMBDA.3, LAMBDA.4, LAMBDA.5, LAMBDA.6, LAMBDA.7, LAMBDA.8, LAMBDA.9, LAMBDA.10, LAMBDA.21, LAMBDA.22, LAMBDA.54, LAMBDA.57, LAMBDA.63, LAMBDA.64 }}}
I will attach the version of my patch which I tested with which has the following changes to https://github.com/armedbear/abcl/pull/11/files
1. Export JSS:*INHIBIT-JSS-OPTIMIZATION*; have it default to T 2. Revbump the JSS ASDF definition.
-- Ticket URL: http://abcl.org/trac/ticket/420#comment:2 armedbear http://abcl.org armedbear
#420: Add ability to optimize function calls with lambda in function position. Use it to optimize jss ------------------------------+-------------------------- Reporter: mevenson | Owner: Type: enhancement | Status: new Priority: major | Milestone: 1.5.0 Component: compiler | Version: 1.5.0-dev Resolution: | Keywords: github-issue Parent Tickets: | ------------------------------+--------------------------
Comment (by aruttenberg):
Updated https://github.com/armedbear/abcl/pull/11
The optimization now checks if the class is defined at compile time, and if not, defers the class lookup to run time.
The test failures were due to the fact that I was transforming (lambda(..) ...) to ((let (...) ...)) instead of (let (...) ...) i.e. one too many parentheses
-- Ticket URL: http://abcl.org/trac/ticket/420#comment:3 armedbear http://abcl.org armedbear
#420: Add ability to optimize function calls with lambda in function position. Use it to optimize jss ------------------------------+-------------------------- Reporter: mevenson | Owner: Type: enhancement | Status: closed Priority: major | Milestone: 1.5.0 Component: compiler | Version: 1.5.0-dev Resolution: fixed | Keywords: github-issue Parent Tickets: | ------------------------------+-------------------------- Changes (by mevenson):
* status: new => closed * resolution: => fixed
Comment:
Implemented with http://abcl.org/trac/changeset/14911.
-- Ticket URL: http://abcl.org/trac/ticket/420#comment:4 armedbear http://abcl.org armedbear
armedbear-ticket@common-lisp.net