performance todo's

This commit is contained in:
Irmen de Jong 2020-05-08 20:15:28 +02:00
parent 534b5ced8f
commit a94bc40ab0
3 changed files with 5 additions and 3 deletions

View File

@ -54,6 +54,7 @@ interface INameScope {
fun linkParents(parent: Node)
fun subScopes(): Map<String, INameScope> {
// TODO PERFORMANCE: this is called very often and is relatively expensive. Optimize this.
val subscopes = mutableMapOf<String, INameScope>()
for(stmt in statements) {
when(stmt) {
@ -126,7 +127,7 @@ interface INameScope {
for(module in localContext.definingModule().program.modules) {
var scope: INameScope? = module
for(name in scopedName.dropLast(1)) {
scope = scope?.subScopes()?.get(name)
scope = scope?.subScopes()?.get(name) // TODO PERFORMANCE: EXPENSIVE! (creates new map every call) OPTIMIZE.
if(scope==null)
break
}

View File

@ -29,7 +29,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
val subroutinesCalling = mutableMapOf<INameScope, List<Subroutine>>().withDefault { mutableListOf() }
val subroutinesCalledBy = mutableMapOf<Subroutine, List<Node>>().withDefault { mutableListOf() }
// TODO add dataflow graph: what statements use what variables
// TODO add dataflow graph: what statements use what variables - can be used to eliminate unused vars
val usedSymbols = mutableSetOf<Statement>()
init {

View File

@ -24,7 +24,7 @@ internal class StatementOptimizer(private val program: Program,
private set
private val pureBuiltinFunctions = BuiltinFunctions.filter { it.value.pure }
private val callgraph = CallGraph(program)
private val callgraph = CallGraph(program) // TODO PERFORMANCE: it is expensive to create this every round
private val vardeclsToRemove = mutableListOf<VarDecl>()
override fun visit(program: Program) {
@ -37,6 +37,7 @@ internal class StatementOptimizer(private val program: Program,
}
private fun removeUnusedCode(callgraph: CallGraph) {
// TODO PERFORMANCE: expensive code (because of callgraph) OPTIMIZE THIS: only run once separately ?
// remove all subroutines that aren't called, or are empty
val removeSubroutines = mutableSetOf<Subroutine>()
val entrypoint = program.entrypoint()