Skip to content

Cell.write and Layout.write are very slow on Windows if there are gigantic polygons in the cell #1853

@sebastian-goeldi

Description

@sebastian-goeldi

Without further ado, here's a small test case

import klayout.db as kdb

ly = kdb.Layout()
test_cell = ly.create_cell("HUGERING")

p_outer = kdb.DPoint(100, 0)
p_hole = kdb.DPoint(96, 0)

poly = kdb.DPolygon(
    [
        kdb.DCplxTrans(1, 360 * angle / 100_000, False, 0, 0) * p_outer
        for angle in range(100_000)
    ]
)
poly.insert_hole(
    [
        kdb.DCplxTrans(1, 360 * angle / 100_000, False, 0, 0) * p_hole
        for angle in range(100_000)
    ]
)

test_cell.shapes(ly.layer(1, 0)).insert(poly)
test_cell.write(
    "test.gds"
)  # super fast on linux (~1.1 sec), super slow on windows (~29 sec)

On Windows this is incredibly slow compared to Linux (tested on arch and debian) - 29+ sec vs 1.1 sec on linux

This also is the case for ly.write.

Interestingly if the polygon is split with the new break_ function first, it's similar speed on both platforms:

polys = poly.break_(4000, 0)
for poly in polys:
     test_cell.shapes(ly.layer(1, 0)).insert(poly)
test_cell.write("test.gds")

I suspect write is getting compiled funnily on Windows and is doing something very inefficient that probably will not matter much if the polygon only needs splitting very few times for the GDS.

Initially discovered here gdsfactory/gdsfactory#3088

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions