Title: [247339] trunk/Source/WebCore
- Revision
- 247339
- Author
- [email protected]
- Date
- 2019-07-10 18:18:14 -0700 (Wed, 10 Jul 2019)
Log 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (247338 => 247339)
--- trunk/Source/WebCore/ChangeLog 2019-07-11 00:59:10 UTC (rev 247338)
+++ trunk/Source/WebCore/ChangeLog 2019-07-11 01:18:14 UTC (rev 247339)
@@ -1,3 +1,21 @@
+2019-07-10 Robin Morisset <[email protected]>
+
+ [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:
+
2019-07-10 Sihui Liu <[email protected]>
Crash at WebCore::IDBServer::MemoryObjectStoreCursor::incrementReverseIterator
Modified: trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp (247338 => 247339)
--- trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp 2019-07-11 00:59:10 UTC (rev 247338)
+++ trunk/Source/WebCore/Modules/webgpu/WHLSL/WHLSLRecursionChecker.cpp 2019-07-11 01:18:14 UTC (rev 247339)
@@ -40,9 +40,18 @@
// Makes sure there is no function recursion.
class RecursionChecker : public Visitor {
private:
+ void visit(Program& program) override
+ {
+ for (auto& functionDefinition : program.functionDefinitions())
+ checkErrorAndVisit(functionDefinition);
+ }
+
void visit(AST::FunctionDefinition& functionDefinition) override
{
- auto addResult = m_visitingSet.add(&functionDefinition);
+ if (m_finishedVisiting.contains(&functionDefinition))
+ return;
+
+ auto addResult = m_startedVisiting.add(&functionDefinition);
if (!addResult.isNewEntry) {
setError();
return;
@@ -49,11 +58,11 @@
}
Visitor::visit(functionDefinition);
- if (error())
- return;
- auto success = m_visitingSet.remove(&functionDefinition);
- ASSERT_UNUSED(success, success);
+ {
+ auto addResult = m_finishedVisiting.add(&functionDefinition);
+ ASSERT_UNUSED(addResult, addResult.isNewEntry);
+ }
}
void visit(AST::CallExpression& callExpression) override
@@ -63,7 +72,8 @@
checkErrorAndVisit(downcast<AST::FunctionDefinition>(callExpression.function()));
}
- HashSet<AST::FunctionDefinition*> m_visitingSet;
+ HashSet<AST::FunctionDefinition*> m_startedVisiting;
+ HashSet<AST::FunctionDefinition*> m_finishedVisiting;
};
bool checkRecursion(Program& program)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes