Open Bug 1265992 Opened 10 years ago Updated 2 years ago

Shorten self-hosted functions related to bug 887016 to make them inlinable.

Categories

(Core :: JavaScript Engine: JIT, defect, P5)

defect

Tracking

()

Tracking Status
firefox48 --- affected

People

(Reporter: arai, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 obsolete file)

(I'm not sure if this bug is valid or not. comments are welcome) Here's the list of self-hosted functions and its script length (in non-debug build) related to bug 887016. [RegExp#exec] RegExpBuiltinExec 375 RegExpExec 139 RegExp_prototype_Exec 112 [RegExp#test] RegExpTest 109 [String#match] IsStringMatchOptimizable 77 StringProtoHasNoMatch 76 String_match 399 [RegExp#@@match] RegExpMatch 378 [String#search] IsStringSearchOptimizable 77 StringProtoHasNoSearch 76 String_search 343 [RegExp#@@search] IsRegExpMethodOptimizable 77 RegExpSearch 280 [String#replace] StringProtoHasNoReplace 76 String_replace 612 [RegExp#@@replace] IsRegExpMethodOptimizable 77 RegExpGlobalReplaceOpt 351 RegExpGlobalReplaceShortOpt 320 RegExpLocalReplaceOpt 287 RegExpReplace 1644 [String#split] StringProtoHasNoSplit 76 String_split 375 [RegExp#@@split] IsRegExpSplitOptimizable 84 SpeciesConstructor 155 RegExpSpecies 12 RegExpSplit 1079 The problems are following (1st one is the biggest problem): * RegExpReplace and RegExpSplit exceeed inlineMaxBytecodePerCallSiteOffThread_ (1000) * String_replace exceeds inlineMaxBytecodePerCallSiteMainThread_ (500) * Many functions exceed smallFunctionMaxBytecodeLength_ (120) Those issues make it hard to perform constant folding and eliminate unused branch, related to following bugs: * (bug 1263340) global/sticky access can be changed to use internal slot, and it means we can fold them into a constant if the RegExp object is a constant. * (bug 1263490) the value of firstDollarIndex can be folded into a int32 constant if replaceValue is a constant string RegExpReplace can be shorten after bug 1264264 gets fixed, as it adds optimized path for most normal cases, and not-optimized path can be moved into different function.
A few potential solutions to start this discussion. Note: this isn't a complete list. 1) Make sure we can annotate selfhosted functions with info, like we currently do with DOM calls. This will make it possible to annotate a function with "movable/uneffectfull/...". Maybe we can even add a "always inline" flag. Pro: Quite easy and effective Cons: Sort of a shortcut. This increases the difference between selfhosted code and normal js code. While it would be better to improve our heuristics or to add more analysis... This would help all JS code. 2) Make sure we have global inlining heuristics. We currently only have local inlining heuristics. Pro: This is something that we already want a long time. Cons: Quite hard in our current system :( 3) Use another metric instead of bytecode length? MIR nodes? assembly code length? The limit is first to make sure we aren't too long on the mainthread to create the graph and secondly since compilation is thought to take 0(n^2). So smaller graphs are compiled faster (which is important for JIT compiler). But "bytecode length != #MIR nodes". Some bytecodes are translated in 0-x MIR nodes. E.g. pgo will remove a lot of nodes, inlining natives .... Pros: Having a better metric, might give us better working heuristics in the current system. Cons: bytecode length is handy, since it always known and doesn't change. MIR node count changes with TI changes etc... ...
About (1), I'll try investigating the possible performance improvement, and see if it's easy to choose functions to annotate "always inline" etc. I need to learn about current heuristics before thinking (2). About (3), if we use the number of MIR nodes or assembly code length, when do those information become available? Is it available (or at least previously known) at the point of considering inlining?
In Octane RegExp, there are so much case that caller is excessively large. DontInline is called in the Heuristics section in IonBuilder::makeInliningDecision for following self-hosted functions: count | function | reason -------+-----------------------------+---------------------------------- 341 | String#replace | caller excessively large 17 | String#split | caller excessively large 3 | String#match | caller excessively large 3 | RegExp#@@match | exceeding allowed script inline depth 2 | RegExpGlobalReplaceShortOpt | caller excessively large 2 | RegExp#@@split | callee excessively large 2 | RegExp#@@replace | callee excessively large 1 | RegExpLocalReplaceOpt | caller excessively large iiuc, the count of RegExp methods are small because String methods are not inlined. Octane RegExp uses large function and calls so much String methods there. https://github.com/h4writer/arewefastyet/blob/master/benchmarks/octane/regexp.js This won't be a good situation for inlining, as MIR becomes huge if I inline them forcibly. Anyway, this particular case cannot be solved just by shortening self-hosted function itself. Will check other cases.
(In reply to Hannes Verschore [:h4writer] from comment #1) > 3) Use another metric instead of bytecode length? MIR nodes? assembly code > length? The limit is first to make sure we aren't too long on the mainthread > to create the graph and secondly since compilation is thought to take > 0(n^2). So smaller graphs are compiled faster (which is important for JIT > compiler). But "bytecode length != #MIR nodes". Some bytecodes are > translated in 0-x MIR nodes. E.g. pgo will remove a lot of nodes, inlining > natives .... Yes! A few operations, like Math.fround() (GetGlobal + CallProp) or SIMD.Float32x4.add (GetGlobal + GetProp + CallProp) will bloat the bytecode length. As a matter of fact, SIMD benchmarking is quite hard to achieve now because of this heuristic: usually, a function manipulating SIMD will use several SIMD operations, and if each of them is using the long form (I am not saying developers *should* do that), this will block SIMD inlining at all! It could also be useful for inlining of other methods on global objects. There was a bug describing this problem more in depth, but I can't seem to find it.
Priority: -- → P5
Severity: normal → S3
Attachment #9385879 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: