Skip to content

DRC deep mode performance regression depending on number of live layers #2569

Backlog

Description

@FlinkbaumFAU

DRC deep-mode performance analysis

Hello,

I wanted to share with you the result of a small performance analysis that I did, as well as some suggestions for a performance improvement.
I was profiling the DRCs of the IHP-Open-PDK in an attempt to speed things up. I noticed, that the bulk of the time is spent in the ext_enlarge_inside function, where the time the function needed was depending on when it was called during the checks, which led me to investigate things further.

Reproducing the timing annomaly

The following code-block tries to reproduce the timing differences I encountered in the official PDK. It features a grow-function, which, just like ext_enlarge_insde, stepwise grows a shape within the boundaries of another shape. The grow function is timed once at the beginning of the benchmark and once after the addition of $nkeep-number of layers. As input I used a custom sram block ihp_sram_256bit_1rw_8x32_8.gds.gz.

source($input)
$mode == "flat" ? flat : deep
cont = source.polygons("6/0")
act  = source.polygons("1/0") - source.polygons("5/0")
def grow(seed, other, steps, step)
  l = seed.dup
  steps.times { l = l.sized(step) & other }
  l
end
t = Time.now; r = grow(cont, act, 29, 0.21.um); t1 = Time.now - t
keep = []
($nkeep || "0").to_i.times { |i| keep << (act.sized((i % 50 + 1) * 0.001.um) & cont) }
t = Time.now; r2 = grow(cont, act, 29, 0.21.um); t2 = Time.now - t
puts "mode=#{$mode} nkeep=#{$nkeep} fresh=#{'%.3f' % t1}s after=#{'%.3f' % t2}s same=#{(r ^ r2).is_empty?} flatcount=#{r.data.count}"

The results show that the perfomance of klayout in deep-mode heavily depends on the number of layers:

Extra live layers (nkeep) deep flat
0 0.50 s 0.87 s
100 0.72 s
250 1.31 s
500 3.62 s
1000 9.34 s 0.88 s

Perf and flamegraphs

Note

I did rely quite heavily on AI for this one. My knowledge of perf and flamegraphs is too limited. I used it to find the right perf options and for collapsing the ruby part of the flamegraphs.

I ran perf as perf record -F 250 --call-graph dwarf,16384 -o <ouput-file> ... and used flamephraphs to visualize it. The first one is for the complete benchmark, for the second one perf was only enabled for the second grow-call. The resulting svgs are interactive, but github renders them as images, so I put them here to download.

deck_master.svg.gz
grow_master.svg.gz

deck_master grow_master

The graphs show how the majority of the time is spent in db::Layout::do_update, which itself spends its time in Cell::is_shape_bbox_dirty, Cell::update_bbox and Cell::sort_shapes, which makes them the best place to start optimizing.

Suggestion

I'm working on a patch that'll try to:

  1. Make is_shape_bbox_dirty run in constant time by giving the cells a dirty flag
  2. Introduce per-layer update. update_bbox should only recompute boxes of dirty layers and keep the rest
  3. Only sort changed cells, and in them only dirty layers

Please let me know your thoughts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions