Skip to content

Quantifying over map.Keys has quadratic runtime in Java #4010

Open
@robin-aws

Description

@robin-aws

Dafny version

4.1.0

Code to produce this issue

method Main() {
  var s := seq(100_000, x => x);
  var m := map k <- s :: k := k;
  var m2 := map k <- m.Keys :: k + 10 := k;
}

Command to run and resulting output

% dafny run -t:java src/Scratch.dfy

What happened?

Command takes about 2 minutes to complete. Replacing m.Keys with m makes it take 10 seconds.

Root cause appears to be translating m.Keys to DafnyMap.keySet(), which makes a defensive copy of the underlying map's key set.

What type of operating system are you experiencing the problem on?

Mac

Metadata

Metadata

Assignees

Labels

area: performancePerformance issueskind: bugCrashes, unsoundness, incorrect output, etc. If possible, add a `part:` labellang: javaDafny's Java transpiler and its runtimepart: code-generationSupport for transpiling Dafny to another language. If relevant, add a `lang:` tagpriority: nextWill consider working on this after in progress work is done

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions