Changeset 247339 in webkit


Ignore:
Timestamp:
Jul 10, 2019 6:18:14 PM (5 years ago)
Author:
rmorisset@apple.com
Message:

[WHLSL] The recursion checker should not have quadratic complexity
https://bugs.webkit.org/show_bug.cgi?id=199688

Reviewed by Saam Barati.

I fix it by using two different hash sets, tracking which functions we have started visiting, and which we have finished visiting.
The difference are those that are currently "on the stack", and calling any of those is an error.
As a bonus, I also overrode visit(Program&), so that we only bother visiting function definitions.

On whlsl-compute.html ran 5 times, this patch reduces the time spent in the recursion checker from 26ms to 12ms.
It is likely to be a much bigger win on larger programs (since it took the complexity from quadratic to linear).

No new tests as there is no intended functional change.

  • Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp:
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247337 r247339  
     12019-07-10  Robin Morisset  <rmorisset@apple.com>
     2
     3        [WHLSL] The recursion checker should not have quadratic complexity
     4        https://bugs.webkit.org/show_bug.cgi?id=199688
     5
     6        Reviewed by Saam Barati.
     7
     8        I fix it by using two different hash sets, tracking which functions we have started visiting, and which we have finished visiting.
     9        The difference are those that are currently "on the stack", and calling any of those is an error.
     10        As a bonus, I also overrode visit(Program&), so that we only bother visiting function definitions.
     11
     12        On whlsl-compute.html ran 5 times, this patch reduces the time spent in the recursion checker from 26ms to 12ms.
     13        It is likely to be a much bigger win on larger programs (since it took the complexity from quadratic to linear).
     14
     15        No new tests as there is no intended functional change.
     16
     17        * Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp:
     18
    1192019-07-10  Sihui Liu  <sihui_liu@apple.com>
    220
  • trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp

    r247254 r247339  
    4141class RecursionChecker : public Visitor {
    4242private:
     43    void visit(Program& program) override
     44    {
     45        for (auto& functionDefinition : program.functionDefinitions())
     46            checkErrorAndVisit(functionDefinition);
     47    }
     48
    4349    void visit(AST::FunctionDefinition& functionDefinition) override
    4450    {
    45         auto addResult = m_visitingSet.add(&functionDefinition);
     51        if (m_finishedVisiting.contains(&functionDefinition))
     52            return;
     53
     54        auto addResult = m_startedVisiting.add(&functionDefinition);
    4655        if (!addResult.isNewEntry) {
    4756            setError();
     
    5059
    5160        Visitor::visit(functionDefinition);
    52         if (error())
    53             return;
    5461
    55         auto success = m_visitingSet.remove(&functionDefinition);
    56         ASSERT_UNUSED(success, success);
     62        {
     63            auto addResult = m_finishedVisiting.add(&functionDefinition);
     64            ASSERT_UNUSED(addResult, addResult.isNewEntry);
     65        }
    5766    }
    5867
     
    6473    }
    6574
    66     HashSet<AST::FunctionDefinition*> m_visitingSet;
     75    HashSet<AST::FunctionDefinition*> m_startedVisiting;
     76    HashSet<AST::FunctionDefinition*> m_finishedVisiting;
    6777};
    6878
Note: See TracChangeset for help on using the changeset viewer.