cp icon indicating copy to clipboard operation
cp copied to clipboard

The optimization of locks in BBQuery

Open fananchong opened this issue 1 year ago • 1 comments

Can

func (space *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{}) {
	context := BBQueryContext{bb, filter, f}
	space.Lock()

	space.staticShapes.class.Query(&context, bb, space.bbQuery, data)
	space.dynamicShapes.class.Query(&context, bb, space.bbQuery, data)

	space.Unlock(true)
}

be optimized to :

func (space *Space) BBQuery(bb BB, filter ShapeFilter, f SpaceBBQueryFunc, data interface{}) {
	context := BBQueryContext{bb, filter, f}

	space.staticShapes.class.Query(&context, bb, space.bbQuery, data)
	
	space.Lock()
	space.dynamicShapes.class.Query(&context, bb, space.bbQuery, data)
	space.Unlock(true)
}

fananchong avatar Jan 19 '24 02:01 fananchong

Since this is a port, I'd rather not add optimizations unless it's first accepted upstream:

https://github.com/slembcke/Chipmunk2D/blob/d0239ef4599b3688a5a336373f7d0a68426414ba/src/cpSpaceQuery.c#L233-L246

jakecoffman avatar Feb 26 '24 14:02 jakecoffman