Managing the size of your Comp’s bounding box is one of the lowest-effort things you can do to find massive performance gains in Nuke. There are a few things we can do to stop processing extra, unseen pixels, and speed up your comp.
1. Find your oversized bounding boxes.
An often unknown feature in Nuke is the Bounding Box warning. Enable this in Nuke’s preferences, and any node with a bounding box that’s larger than the Nuke script’s root format + this specified threshold will be highlighted.
This feature is great to find problem nodes and add crops after them, however, it will slow down the performance of your Nuke script if you leave it on. Ensure you turn it off after you finish finding and fixing all your large bboxes!
If you would like to set a hotkey to toggle this feature on/off, here is some code.
Tip: Be careful of cropping everything to the format’s size, as you can easily eliminate overscan which is needed for downstream Lens Distortion nodes. I whipped up a Crop_Overscan node to help you crop bounding boxes while preserving overscan, however, I’d encourage you to experiment with using the CopyBBox node, too. Sometimes copying the bbox directly from an upstream Read node is a simple way to keep it as tight as possible!
2. Optimize your node defaults.
By default, most nodes set the bounding box to union. Oftentimes, we can set better defaults that will automatically stop our bbox ballooning in size. For example, when we create a Merge node using the over operation, we can almost always safely keep the bbox from the B pipe. If we switch the operation to mask, we should use the bbox from the A pipe.
To speed up my workflow, I have set some keyboard shortcuts in my menu.py, which create Merge nodes with different operations & appropriate bbox settings. For example:
# Set the merge node's "set bbox to" knob to "B" by default. nuke.knobDefault('Merge2.bbox', 'B') # alt+i shortcut to create Merge node with "mask" operation nuke.menu('Nodes').addMenu('Merge/Merges').addCommand('Mask', 'nuke.createNode("Merge2", "operation mask bbox A", False)', "alt+i", icon="In.png", shortcutContext=2) # alt+o shortcut to create Merge node with "mask" operation nuke.menu('Nodes').addMenu('Merge/Merges').addCommand('Stencil', 'nuke.createNode("Merge2", "operation stencil bbox B", False)', "alt+o", icon="Out.png", shortcutContext=2)
We can extend this thinking to other nodes as well. For example, it would make sense to have a Copy node always get the bbox from the A pipe.
3. Automate it!
While it’s good practice to manage your bounding box size as you comp, not every Compositor does it. If you’ve picked up someone else’s Nuke script and it’s running slowly, it can be a pain to manually find & fix every large bounding box. In this case, you could automate it!
To serve as inspiration, I’ve put together a rough Python script that will automatically find and crop (with X% overscan) any oversized bounding box in every Merge node’s A pipe. You can download that from Github here!
(Download a simple sample Nuke script to test it on here)