Experiment with making Python go faster

The goal is to put the compiled pyc files in the APE ZIP.
This commit is contained in:
Justine Tunney 2021-08-18 21:57:11 -07:00
parent 4486ad5c9e
commit ebb8c85496
33 changed files with 9483 additions and 1859 deletions

View file

@ -466,6 +466,7 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home,
static void
calculate_path(void)
{
#if 0
static wchar_t delimiter[2] = {DELIM, '\0'};
static wchar_t separator[2] = {SEP, '\0'};
/* ignore PYTHONPATH/PYTHONHOME for now */
@ -486,21 +487,17 @@ calculate_path(void)
size_t ape_length;
wchar_t ape_lib_path[MAXPATHLEN+1];
wchar_t ape_exec_path[MAXPATHLEN+1];
wchar_t package_path[MAXPATHLEN+1];
wchar_t ape_package_path[MAXPATHLEN+1];
if(IsWindows())
{
delimiter[0] = L';';
separator[0] = L'\\';
}
if (_path) {
path_buffer = Py_DecodeLocale(_path, NULL);
path = path_buffer;
}
/* If there is no slash in the argv0 path, then we have to
* assume python is on the user's $PATH, since there's no
* other way to find a directory to start the search from. If
@ -511,7 +508,6 @@ calculate_path(void)
else if (path) {
while (1) {
wchar_t *delim = wcschr(path, DELIM);
if (delim) {
size_t len = delim - path;
if (len > MAXPATHLEN)
@ -521,11 +517,9 @@ calculate_path(void)
}
else
wcsncpy(progpath, path, MAXPATHLEN);
joinpath(progpath, prog);
if (isxfile(progpath))
break;
if (!delim) {
progpath[0] = L'\0';
break;
@ -540,27 +534,21 @@ calculate_path(void)
absolutize(progpath);
wcsncpy(argv0_path, progpath, MAXPATHLEN);
argv0_path[MAXPATHLEN] = '\0';
reduce(argv0_path);
/* At this point, argv0_path is guaranteed to be less than
MAXPATHLEN bytes long.
*/
/* not searching for pyvenv.cfg */
/* Avoid absolute path for prefix */
wcsncpy(prefix,
L"third_party/python/Lib",
MAXPATHLEN);
/* wcsncpy(prefix, */
/* L"zip!third_party/python/Lib/", */
/* MAXPATHLEN); */
wcsncpy(prefix,
L"zip!.python",
MAXPATHLEN);
/* Avoid absolute path for exec_prefix */
wcsncpy(exec_prefix, L"build/lib.linux-x86_64-3.6", MAXPATHLEN);
wcsncpy(package_path, L"Lib/site-packages", MAXPATHLEN);
// printf("progpath = %ls, prog = %ls\n", progpath, prog);
/* add paths for the internal store of the APE */
if(wcslen(progpath) > 0 && wcslen(progpath) + 1 < MAXPATHLEN)
@ -568,7 +556,6 @@ calculate_path(void)
else
wcsncpy(ape_path, prog, MAXPATHLEN);
ape_length = wcslen(ape_path);
wcsncpy(ape_lib_path, ape_path, MAXPATHLEN);
// extra 1 at the start for the slash
if(ape_length + 1 + wcslen(prefix) + 1 < MAXPATHLEN)
@ -576,24 +563,20 @@ calculate_path(void)
ape_lib_path[ape_length] = L'/';
wcscat(ape_lib_path + ape_length + 1, prefix);
}
wcsncpy(ape_exec_path, ape_path, MAXPATHLEN);
if(ape_length + 1 + wcslen(exec_prefix) + 1 < MAXPATHLEN)
{
ape_exec_path[ape_length] = L'/';
wcscat(ape_exec_path + ape_length + 1, exec_prefix);
}
wcsncpy(ape_package_path, ape_path, MAXPATHLEN);
if(ape_length + 1 + wcslen(package_path) + 1 < MAXPATHLEN)
{
ape_package_path[ape_length] = L'/';
wcscat(ape_package_path + ape_length + 1, package_path);
}
/* Calculate size of return buffer */
bufsz = 0;
bufsz += wcslen(ape_lib_path) + 1;
bufsz += wcslen(ape_exec_path) + 1;
bufsz += wcslen(ape_package_path) + 1;
@ -601,44 +584,36 @@ calculate_path(void)
bufsz += wcslen(prefix) + 1;
bufsz += wcslen(exec_prefix) + 1;
bufsz += wcslen(package_path) + 1;
/* This is the only malloc call in this file */
buf = PyMem_RawMalloc(bufsz * sizeof(wchar_t));
if (buf == NULL) {
Py_FatalError(
"Not enough memory for dynamic PYTHONPATH");
}
buf[0] = L'\0';
wcscat(buf, prefix);
wcscat(buf, delimiter);
wcscat(buf, package_path);
wcscat(buf, delimiter);
wcscat(buf, ape_lib_path);
wcscat(buf, delimiter);
wcscat(buf, ape_package_path);
wcscat(buf, delimiter);
wcscat(buf, ape_exec_path);
wcscat(buf, delimiter);
wcscat(buf, ape_path);
wcscat(buf, delimiter);
/* Finally, on goes the directory for dynamic-load modules */
wcscat(buf, exec_prefix);
/* And publish the results */
module_search_path = buf;
// printf("%ls\n", buf);
#else
module_search_path = L"zip!.python/";
/* module_search_path = L"third_party/python/Lib/"; */
#endif
}
/* External interface */
void
Py_SetPath(const wchar_t *path)