[ https://issues.apache.org/jira/browse/LUCENE-9395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tony Xu updated LUCENE-9395: ---------------------------- Description: At day job, we use ConstantValuesSource to represent default values or a constant query-level feature by calling *_DoubleValuesSource.constant_*. I realized under the hood the _*ConstantValuesSource.getDoubleValues*_ creates a new _*DoubleValues*_ which simply return the specified value each time it is called. Unless I missed something, I don't see a risk of creating one _*DoubleValues*_ as use it as the return value of all _*getDoubleValues**()*_ calls given that the constant _*DoubleValues*_ doesn't maintain any state. We can also offer the user flexibilities of how to initialize it. 1) _*DoubleValuesSource.constant(double constant)*_ – we can eagerly initialize an `DoubleValues` that returns the constant and make it the return value of all _*getDoubleValues()*_ calls. 2) _*DoubleValuesSource.constant(DoubleSupplier doubleSupplier)*_ – For lazy evaluation if the constant takes some time to compute and user expects the returned DVS will not be used in all code path. was: At my work we use ConstantValuesSource to represent default values or a constant query-level feature by calling `DoubleValuesSource.constant`. I realized under the hood the `ConstantValuesSource.getDoubleValues` creates a new `DoubleValues` which simply return the specified value each time it is called. Unless I missed something, I don't see risk of creating one `DoubleValues` as use it as the return value of all getDoubleValues() calls given that the `DoubleValues` doesn't maintain any state. We can also offer the user flexibilities of how to initialize it. 1) `DoubleValuesSource.constant(double constant)` – we can eagerly initialize an `DoubleValues` that returns the constant and make it the return value of all getDoubleValues() calls. 2) `DoubleValuesSource.constant(DoubleSupplier supplier)` – For lazy evaluation if the constant takes some time to compute and user expects the returned DVS will not be used in all code path. > ConstantValuesSource creates more than one DoubleValues unnecessarily > ---------------------------------------------------------------------- > > Key: LUCENE-9395 > URL: https://issues.apache.org/jira/browse/LUCENE-9395 > Project: Lucene - Core > Issue Type: Improvement > Components: core/search > Affects Versions: 8.5.2 > Reporter: Tony Xu > Priority: Minor > > At day job, we use ConstantValuesSource to represent default values or a > constant query-level feature by calling *_DoubleValuesSource.constant_*. I > realized under the hood the _*ConstantValuesSource.getDoubleValues*_ creates > a new _*DoubleValues*_ which simply return the specified value each time it > is called. > Unless I missed something, I don't see a risk of creating one > _*DoubleValues*_ as use it as the return value of all _*getDoubleValues**()*_ > calls given that the constant _*DoubleValues*_ doesn't maintain any state. > We can also offer the user flexibilities of how to initialize it. > 1) _*DoubleValuesSource.constant(double constant)*_ – we can eagerly > initialize an `DoubleValues` that returns the constant and make it the return > value of all _*getDoubleValues()*_ calls. > 2) _*DoubleValuesSource.constant(DoubleSupplier doubleSupplier)*_ – For lazy > evaluation if the constant takes some time to compute and user expects the > returned DVS will not be used in all code path. -- This message was sent by Atlassian Jira (v8.3.4#803005) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org