-
Notifications
You must be signed in to change notification settings - Fork 1.1k
avoid duplicate call to dist/bin/common on script startup #11698
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
Conversation
@michelou Are you available to review this? |
Yes. I'll have a look (and do some tests under MingW64).
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philwalk I see no reason to export variable PROG_HOME
and function restoreSettings
on lines 164-167 in file dist/bin/common
.
PS. Personally I would use a function getHome()
to initialize variable PROG_HOME
(see e.g. file build.sh
in my project dotty-examples
).
I agree, there's no reason to export |
Good point about |
This comment has been minimized.
This comment has been minimized.
close-then-open to trigger rebuild due to stalled community build |
I don't have much expertise on this. The complex exports in I am wondering if it is possible to avoid calling |
@liufengyun WRT the exports in |
It seems to me that the two occurrences of If that is the case, then the only significant piece of code is |
I'll experiment with the idea and report what I find (it might take awhile). |
This approach looks promising. I have a Question for anyone who might know the answer. What use-case is supported by the following code, which passes arguments directly to the jvm: In elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then
cp_arg="$DOTTY_LIB$PSEP$SCALA_LIB"
if [ -z "$CLASS_PATH" ]; then
cp_arg+="$PSEP."
else
cp_arg+="$PSEP$CLASS_PATH"
fi
if [ "$class_path_count" -gt 1 ]; then
echo "warning: multiple classpaths are found, scala only use the last one."
fi
if [ $with_compiler == true ]; then
cp_arg+="$PSEP$DOTTY_COMP$PSEP$TASTY_CORE$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$PSEP$DOTTY_STAGING$PSEP$DOTTY_TASTY_INSPECTOR"
fi
# exec here would prevent onExit from being called, leaving terminal in unusable state
eval "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${jvm_options[@]}" "${residual_args[@]}"
scala_exit_status=$? The first test for Perhaps something like this is intended (it works):
We might want to add more CLI filtering since, as it's currently configured, any and all unrecognized command line arguments are captured in *)
if [ $execute_script == false ]; then
# is a script if extension .scala or .sc or if has scala hash bang
if [[ -e "$1" && ("$1" == *.scala || "$1" == *.sc || -f "$1" && `head -n 1 -- "$1" | grep '#!.*scala'`) ]]; then
execute_script=true
target_script="$1"
else
# all unrecognized command line arguments are stored here
residual_args+=("$1")
fi
else
script_args+=("$1")
fi
shift
;;
esac |
I'm getting the following test failure (even with HEAD code, and no modifications): [info] Test dotty.tools.repl.ScriptedTests.replTests started
expected =========>
scala> val d: java.sql.Date = new java.sql.Date(100L)
val d: java.sql.Date = 1970-01-01
actual ===========>
scala> val d: java.sql.Date = new java.sql.Date(100L)
val d: java.sql.Date = 1969-12-31 I'm not sure what it implies. Happens in Windows 10 cygwin and in WSL ubuntu. |
It's probably a timezone issue, feel free to change that test to run |
Here's what #!/usr/bin/env bash
# Try to autodetect real location of the script
if [ -z "$PROG_HOME" ] ; then
## resolve links - $0 may be a link to PROG_HOME
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
PROG_HOME=`dirname "$PRG"`/..
# make it fully qualified
PROG_HOME=`cd "$PROG_HOME" && pwd`
cd "$saveddir"
fi
source "$PROG_HOME/bin/common"
PROG_NAME=$CompilerMain
prepScalacCommandLine "$@"
# exec here would prevent onExit from being called, leaving terminal in unusable state
eval "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${java_args[@]}" "${residual_args[@]}"
scala_exit_status=$? |
I checked in the alternate code here PR #12197 |
Hey @philwalk, does your alternate PR mean we can close this one? |
Yes, I'm about the commit a final change to #12197, so I'll close this. |
This supercedes #11660
When launching a scala3 script, there are two calls to dist/bin/common, the first from within dist/bin/scala and the 2nd when
dist/bin/scala
callsdist/bin/scalac
.It turns out that the avoidable 2nd call is quite expensive in terms of what it adds to script startup latency. Here are the reductions in startup time when running in
cygwin
and inWSL Linux
:The numbers are the difference in startup latency for calling a
hello-world.sc
script with and without the changes in this PR, averaged over 100 runs.The categories of change in the PR are:
dist/bin/common
and required by scalacdist/bin/scalac
to conditionally sourcedist/bin/common
set -o nounset
The third change is exemplified by line 114 in
dist/bin/common
: