This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Intern identifiers of: * function parameter names * function argument names * dot-expression rhs (e. g. `[].append`) We do a lot of hashmap lookups with these strings (e. g. each time we invoke `lll.append(x)`, even with non-identity-hash-map, lookup by identity-equal string is faster (no need to perform deep string comparison). This is exactly the same diff as submitted to Bazel PR, interning is performed with external interner, but since in Buck we do a lot of `String.intern`, probably we should just do `String.intern` in our version instead of external interner. `String.intern` was expensive in old Java days, I'm not sure how good is it nowadays. Upstream PR: bazelbuild/bazel#12521 Reviewed By: mzlee fbshipit-source-id: 25f3feeb216e64269e2226a003a0b9b5695f4c6b
- Loading branch information
1 parent
e4d865d
commit f557d47
Showing
5 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
third-party/java/bazel/src/main/java/net/starlark/java/syntax/StarlarkStringInterner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.starlark.java.syntax; | ||
|
||
import com.google.common.collect.Interner; | ||
import com.google.common.collect.Interners; | ||
|
||
/** | ||
* Common place to intern strings in Starlark interpreter. | ||
* | ||
* <p>Interned strings are much faster to lookup, which is important, for example, when evaluating | ||
* expression {@code foo.bar}. | ||
*/ | ||
public class StarlarkStringInterner { | ||
private StarlarkStringInterner() {} | ||
|
||
private static final Interner<String> INTERNER = Interners.newWeakInterner(); | ||
|
||
/** Weak intern the string. */ | ||
public static String intern(String string) { | ||
return INTERNER.intern(string); | ||
} | ||
} |