Skip to content

Performance issue in FSTIterator.next #32

@pavelbazika

Description

@pavelbazika

Hi,

I'm using bleve full text search, which uses couchbase as backend. Sometimes I observe high CPU consumption taking several minutes, sometimes even golang garbage collector cannot operate. Tracking the issue down pointed to FSTIterator.next method.

There are around ~400.000 items in the statesStack in my instance. All represents linear sequence of nodes (NumTransitions() == 1 for whole list). There was an optimization made by @steveyen in 462e86d which cuts linear sequence of nodes and spares OUTER loop. But it does not do so when all nodes are in linear sequence. Here is the code:

		// if the top of the stack represents a linear chain of states
		// (i.e., a suffix of nodes linked by single transitions),
		// then optimize by popping the suffix in one shot without
		// going back all the way to the OUTER loop
		var popNum int
		for j := len(i.statesStack) - 1; j > 0; j-- {
			if i.statesStack[j].NumTransitions() != 1 {
				popNum = len(i.statesStack) - 1 - j
				break
			}
		}
		if popNum < 1 { // always pop at least 1 entry from the stacks
			popNum = 1
		}

When all nodes are in linear sequence, popNum remains zero and is set to 1 after the cycle. In my opinion the condition is there for the case the stack top would have more transitions, but when all have 1, it causes looping.

Is it a bug in optimization or is it by intent?

Thanks for reviewing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions