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

Escape analysis in the Elisp context #113

Open
quasilyte opened this issue Jan 23, 2018 · 1 comment
Open

Escape analysis in the Elisp context #113

quasilyte opened this issue Jan 23, 2018 · 1 comment

Comments

@quasilyte
Copy link
Owner

quasilyte commented Jan 23, 2018

Allocations affect Emacs Lisp performance significantly.

There is a trick that can optimize away some unnecessary allocations, provided:

  1. We are exploiting single-threaded nature of Emacs Lisp.
  2. We have escape analysis that does not break valid code and can detect safe cases for optimizations.

For the code below:

func f(i, a, b, c, d int) int {
	var xs [4]int{a, b, c, d}
	return xs[i]
}

Naive implementation would allocate [4]int as (vector a b c d) for each invocation.

For this particular case, it is clever to store [nil nil nil nil] in the constant vector and perform 4 aset upon xs initialization. xs never "leak" (escape) away, so no observable effects are changed.

Same scheme can be applied for local objects that do not escape.
Since "true" objects are represented with lists and vectors, they always involve allocations.

This mechanism is not perfect and should not be used for big objects (and arrays).
The exact performance implications are yet to be measured.

Should also handle optimizations outlined in Goism object layout model article.

@quasilyte
Copy link
Owner Author

This is very long-term, but potentially very important for performance.

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

1 participant