Re: Expressions greedy advanceExact implementation
Thanks, yeah I thought so too. Merged On Wed, Oct 26, 2022 at 10:31 AM Robert Muir wrote: > > I think deferring the advance call like this is fine and harmless, > only because this DoubleValues "caches" the result for the current > doc, so its idempotent anyway. > > Yes, about "advancing all the operands" as I mentioned, expressions > has no clue about this. If you wanted to change it, you'd have to push > both advancing AND caching down lower into the actual compiled > expression code. > > I think this would add way too much complexity, especially when it > would only improve the ternary "if" feature in such cases. > > On Wed, Oct 26, 2022 at 10:23 AM Michael Sokolov wrote: > > > > see https://github.com/apache/lucene/pull/11878 ... it doesn't do what > > I initially asked for (still advances all of the operands), but it > > delays until doubleValue() is called, which is safe and could have > > some impact > > > > On Wed, Oct 26, 2022 at 9:58 AM Michael Sokolov wrote: > > > > > > Hi, yes, makes sense Mikhail, that will address most of the problem. > > > But I also think, given the way Expressions work (they always return > > > true from advanceExact) there is no reason for them to advance their > > > operands. This shifts the burden/concern from the developer who no > > > longer has to think as hard about this :) - let me post a PR that > > > shows > > > > > > On Wed, Oct 26, 2022 at 3:52 AM Mikhail Khludnev wrote: > > > > > > > > Hello, Michael. > > > > I suppose you can bind f2 to custom lazy implementation of > > > > DoubleValuesSource, which defer advanceExact() by storing doc num and > > > > returning true always, and actually advancing on doubleValue() only. > > > > > > > > On Tue, Oct 25, 2022 at 8:13 PM Michael Sokolov > > > > wrote: > > > >> > > > >> ExpressionFunctionValueSource lazily evaluates in doubleValues: an > > > >> expression like > > > >> > > > >>condition ? f1 : f2 > > > >> > > > >> will only evaluate one of f1 or f2. > > > >> > > > >> At the same time, the advanceExact() call is greedy -- when you > > > >> advance that expression it will also advance both f1 and f2. But > > > >> here's the thing: it always returns true, regardless of whether f1 and > > > >> f2 advance. Which makes sense from the point of view of the lazy > > > >> evaluation -- if condition is true we don't care whether f2 advances > > > >> or not. > > > >> > > > >> My question is whether we could defer these child advanceExact calls > > > >> until ExpressionFunctionValues.doubleValue()? > > > >> > > > >> - > > > >> To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > > > >> For additional commands, e-mail: dev-h...@lucene.apache.org > > > >> > > > > > > > > > > > > -- > > > > Sincerely yours > > > > Mikhail Khludnev > > > > - > > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > > For additional commands, e-mail: dev-h...@lucene.apache.org > > > > - > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > For additional commands, e-mail: dev-h...@lucene.apache.org > - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
Re: Expressions greedy advanceExact implementation
I think deferring the advance call like this is fine and harmless, only because this DoubleValues "caches" the result for the current doc, so its idempotent anyway. Yes, about "advancing all the operands" as I mentioned, expressions has no clue about this. If you wanted to change it, you'd have to push both advancing AND caching down lower into the actual compiled expression code. I think this would add way too much complexity, especially when it would only improve the ternary "if" feature in such cases. On Wed, Oct 26, 2022 at 10:23 AM Michael Sokolov wrote: > > see https://github.com/apache/lucene/pull/11878 ... it doesn't do what > I initially asked for (still advances all of the operands), but it > delays until doubleValue() is called, which is safe and could have > some impact > > On Wed, Oct 26, 2022 at 9:58 AM Michael Sokolov wrote: > > > > Hi, yes, makes sense Mikhail, that will address most of the problem. > > But I also think, given the way Expressions work (they always return > > true from advanceExact) there is no reason for them to advance their > > operands. This shifts the burden/concern from the developer who no > > longer has to think as hard about this :) - let me post a PR that > > shows > > > > On Wed, Oct 26, 2022 at 3:52 AM Mikhail Khludnev wrote: > > > > > > Hello, Michael. > > > I suppose you can bind f2 to custom lazy implementation of > > > DoubleValuesSource, which defer advanceExact() by storing doc num and > > > returning true always, and actually advancing on doubleValue() only. > > > > > > On Tue, Oct 25, 2022 at 8:13 PM Michael Sokolov > > > wrote: > > >> > > >> ExpressionFunctionValueSource lazily evaluates in doubleValues: an > > >> expression like > > >> > > >>condition ? f1 : f2 > > >> > > >> will only evaluate one of f1 or f2. > > >> > > >> At the same time, the advanceExact() call is greedy -- when you > > >> advance that expression it will also advance both f1 and f2. But > > >> here's the thing: it always returns true, regardless of whether f1 and > > >> f2 advance. Which makes sense from the point of view of the lazy > > >> evaluation -- if condition is true we don't care whether f2 advances > > >> or not. > > >> > > >> My question is whether we could defer these child advanceExact calls > > >> until ExpressionFunctionValues.doubleValue()? > > >> > > >> - > > >> To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > > >> For additional commands, e-mail: dev-h...@lucene.apache.org > > >> > > > > > > > > > -- > > > Sincerely yours > > > Mikhail Khludnev > > - > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > For additional commands, e-mail: dev-h...@lucene.apache.org > - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
Re: Expressions greedy advanceExact implementation
see https://github.com/apache/lucene/pull/11878 ... it doesn't do what I initially asked for (still advances all of the operands), but it delays until doubleValue() is called, which is safe and could have some impact On Wed, Oct 26, 2022 at 9:58 AM Michael Sokolov wrote: > > Hi, yes, makes sense Mikhail, that will address most of the problem. > But I also think, given the way Expressions work (they always return > true from advanceExact) there is no reason for them to advance their > operands. This shifts the burden/concern from the developer who no > longer has to think as hard about this :) - let me post a PR that > shows > > On Wed, Oct 26, 2022 at 3:52 AM Mikhail Khludnev wrote: > > > > Hello, Michael. > > I suppose you can bind f2 to custom lazy implementation of > > DoubleValuesSource, which defer advanceExact() by storing doc num and > > returning true always, and actually advancing on doubleValue() only. > > > > On Tue, Oct 25, 2022 at 8:13 PM Michael Sokolov wrote: > >> > >> ExpressionFunctionValueSource lazily evaluates in doubleValues: an > >> expression like > >> > >>condition ? f1 : f2 > >> > >> will only evaluate one of f1 or f2. > >> > >> At the same time, the advanceExact() call is greedy -- when you > >> advance that expression it will also advance both f1 and f2. But > >> here's the thing: it always returns true, regardless of whether f1 and > >> f2 advance. Which makes sense from the point of view of the lazy > >> evaluation -- if condition is true we don't care whether f2 advances > >> or not. > >> > >> My question is whether we could defer these child advanceExact calls > >> until ExpressionFunctionValues.doubleValue()? > >> > >> - > >> To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > >> For additional commands, e-mail: dev-h...@lucene.apache.org > >> > > > > > > -- > > Sincerely yours > > Mikhail Khludnev - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
Re: Expressions greedy advanceExact implementation
Hi, yes, makes sense Mikhail, that will address most of the problem. But I also think, given the way Expressions work (they always return true from advanceExact) there is no reason for them to advance their operands. This shifts the burden/concern from the developer who no longer has to think as hard about this :) - let me post a PR that shows On Wed, Oct 26, 2022 at 3:52 AM Mikhail Khludnev wrote: > > Hello, Michael. > I suppose you can bind f2 to custom lazy implementation of > DoubleValuesSource, which defer advanceExact() by storing doc num and > returning true always, and actually advancing on doubleValue() only. > > On Tue, Oct 25, 2022 at 8:13 PM Michael Sokolov wrote: >> >> ExpressionFunctionValueSource lazily evaluates in doubleValues: an >> expression like >> >>condition ? f1 : f2 >> >> will only evaluate one of f1 or f2. >> >> At the same time, the advanceExact() call is greedy -- when you >> advance that expression it will also advance both f1 and f2. But >> here's the thing: it always returns true, regardless of whether f1 and >> f2 advance. Which makes sense from the point of view of the lazy >> evaluation -- if condition is true we don't care whether f2 advances >> or not. >> >> My question is whether we could defer these child advanceExact calls >> until ExpressionFunctionValues.doubleValue()? >> >> - >> To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org >> For additional commands, e-mail: dev-h...@lucene.apache.org >> > > > -- > Sincerely yours > Mikhail Khludnev - To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org
Re: Expressions greedy advanceExact implementation
Hello, Michael. I suppose you can bind f2 to custom lazy implementation of DoubleValuesSource, which defer advanceExact() by storing doc num and returning true always, and actually advancing on doubleValue() only. On Tue, Oct 25, 2022 at 8:13 PM Michael Sokolov wrote: > ExpressionFunctionValueSource lazily evaluates in doubleValues: an > expression like > >condition ? f1 : f2 > > will only evaluate one of f1 or f2. > > At the same time, the advanceExact() call is greedy -- when you > advance that expression it will also advance both f1 and f2. But > here's the thing: it always returns true, regardless of whether f1 and > f2 advance. Which makes sense from the point of view of the lazy > evaluation -- if condition is true we don't care whether f2 advances > or not. > > My question is whether we could defer these child advanceExact calls > until ExpressionFunctionValues.doubleValue()? > > - > To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org > For additional commands, e-mail: dev-h...@lucene.apache.org > > -- Sincerely yours Mikhail Khludnev