Skip to content

Instantly share code, notes, and snippets.

View ochafik's full-sized avatar

Olivier Chafik ochafik

View GitHub Profile
@ochafik
ochafik / benchmark results.txt
Last active January 30, 2021 18:38
Experiment w/ fast-union heuristic to break local overlapping barriers
# Context: https://github.com/openscad/openscad/pull/3636
Notice the N=3 vs. N=5 below. All test on a MacBook Pro w/ 2.6GHz Core i7.
# Baseline
time openscad spheres_single_for_loop.scad -o out.stl -DN=3 -Doverlap=true # 52s
time openscad spheres_nested_for_loops.scad -o out.stl -DN=3 -Doverlap=true # 45s
time openscad spheres_single_for_loop.scad -o out.stl -DN=5 -Doverlap=true # 3min32
time openscad spheres_nested_for_loops.scad -o out.stl -DN=5 -Doverlap=true # 2min41
@ochafik
ochafik / compare.sh
Created January 30, 2021 16:04
OpenSCAD benchmarking utility (compares various features and logs times neatly)
#!/bin/bash
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
#
# Author: Olivier Chafik (http://ochafik.com)
#
# Usage:
# - Checkout my optimization integration branch (doesn't include multithreaded changes):
# git clone https://github.com/ochafik/openscad openscad-ochafik
# cd openscad-ochafik
@ochafik
ochafik / chainmail.scad
Last active January 30, 2021 15:21
OpenSCAD Chainmail benchmark for fast-union evaluation
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
//
// Author: Olivier Chafik (http://ochafik.com)
//
// This is extracted from my little chain/scalemail project shared in
// https://gist.github.com/ochafik/6d19e3b131153305b44ea275d5d930e3
//
// It is simpler to render, this example is crafted to exercice the fast-union
// feature I'm proposing in https://github.com/openscad/openscad/pull/3636
@ochafik
ochafik / _scalemail_10x10_heart.png
Last active February 14, 2021 03:32
An OpenSCAD model of scalemail (source included below) that benefits from rendering optimizations under development.
_scalemail_10x10_heart.png
@ochafik
ochafik / uncacheable_pattern.scad
Last active January 29, 2021 13:56
OpenSCAD file with an irregular pattern
// Context: ochafik@'s attempts to speed up OpenSCAD
// fast-union feature: https://github.com/openscad/openscad/pull/3636
// lazier union features: https://github.com/openscad/openscad/pull/3637
//
// (and parallelization attempts, not sent as PRs yet)
//
// fast-union, lazy-union, push-transforms-down-unions, lazy-module and flatten-children all help here!
// openscad --enable=fast-union cube-with-half-spheres-dents.scad -o cube-with-half-spheres-dents.stl
top_transform = true;
@ochafik
ochafik / README.md
Last active December 10, 2024 07:01
OpenSCAD Examples sped up by fast-csg feature

Here are some micro benchmarks that demonstrate big gains of OpenSCAD rendering with --enable=fast-csg (a feature I developed in this pull request).

Note: some (but not all) models making heavy use of minkowski may be slower with the feature enabled, as CGALUtils::applyMinkowski is forcing conversions to the old nef format. I hope to address that + publish benchmarks involving minkowski operations soon!*

Note2: these figures need updating, lots of changes since last time I tested these files! Most notably, I'm now proactively falling back to Nef computations in many cases that could have been handled by fast PMP operations on surface meshes, just by fear of hitting corner cases that might corrupt the data. Makes things slower :-(

  • uncacheable-grid.scad (see below): 35sec -> 1.5sec (31x faster)
  • chainmail.scad (see below): 24min 15sec -> 4min 27sec (5x faster)
  • spheres_nested_for_loops.scad (see below): 44sec
@ochafik
ochafik / variable_pattern.scad
Last active January 30, 2021 14:02
Some stress test for lazier unions
// Copyright 2021 Google LLC.
// SPDX-License-Identifier: Apache-2.0
//
/*
This model exercices a few experimental features I've been brewing.
It's not a theoretical case tho: I was trying to print a chainmail with
variable tiles when OpenSCAD's rendering scalability challenges hit me hard :-S
(guess I fell down the rabbit hole of 3d rendering optimization at the
temporary expense of my 3d printing projects, oh well!)
@ochafik
ochafik / README.md
Last active February 3, 2022 01:27
Build an optimized OpenSCAD locally on MacOS X (checkout parallel fork)
mkdir build
( cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DEXPERIMENTAL=1 )
( cd build && time make -j12 )
( cd build/tests && time ctest -j12 -E 'edges_view-options-tests|nef3_broken' )
( cd build/tests && time ctest -j12 -R 'fastcsg.*' )
@ochafik
ochafik / test.dart
Last active February 4, 2020 14:26
dart:js doesn't unwrap IntersectionObserver
import 'dart:js';
import 'dart:html';
main() {
printJsObject(o) =>
(JsObject(context['Function'], ['console.log(arguments[0])']) as JsFunction).apply([o]);
printJsObject(DivElement());
// prints <div></div>
@ochafik
ochafik / main.dart
Created February 4, 2020 14:18
dart:js IntersectionObserver unwrapping bug
import 'dart:js';
import 'dart:html';
main() {
printJsObject(document.body);
var o = IntersectionObserver((entries, observer) {
printJsObject(observer);
printJsObject(JsObject.fromBrowserObject(observer));
for (final entry in entries) {
printJsObject(entry);