Skip to content

Master formula function ref assert and errors laa #6248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

laa-odoo
Copy link
Collaborator

@laa-odoo laa-odoo commented Apr 29, 2025

Task: 4760596

@robodoo
Copy link
Collaborator

robodoo commented Apr 29, 2025

Pull request status dashboard

@laa-odoo laa-odoo force-pushed the master-formula-function-ref-assert-and-errors-laa branch 11 times, most recently from c396d46 to bff4dac Compare April 29, 2025 14:42
@rrahir
Copy link
Collaborator

rrahir commented Apr 29, 2025

I apologize if I missed something obvious, I justquickly went over the diff. Is there a reason why we keep some asserts in given situations? If so, it could be worth mentioning it somewhere (commit message and/or codebase if relevant?)

unrelated to the content but still worth mentioning:

  • there are typos in the commit message
  • @anhe-odoo is not properly credited as a co-author, the correct syntax is {username} <{githubAccountemail}>
    in this case, Anthony Hendrickx (anhe) <[email protected]>

@laa-odoo
Copy link
Collaborator Author

laa-odoo commented May 2, 2025

I apologize if I missed something obvious, I justquickly went over the diff. Is there a reason why we keep some asserts in given situations? If so, it could be worth mentioning it somewhere (commit message and/or codebase if relevant?)

unrelated to the content but still worth mentioning:

  • there are typos in the commit message
  • @anhe-odoo is not properly credited as a co-author, the correct syntax is {username} <{githubAccountemail}>
    in this case, Anthony Hendrickx (anhe) <[email protected]>

Initially, the compute time spent handling errors in formulas was unusually high.
This happened mainly for two reasons:

  • Creating errors from native JavaScript errors is very costly.
  • Throwing errors is also costly (but still less than the first point).

At the same time, we had a unification problem: in all the code that implements formulas, we had several ways to handle errors:

  • Using throw with the error we want
  • Using return with the error we want
  • Using assert, which throws specific errors (more elegant than a simple throw after a condition)

Note that there is also a technical constraint: it is not possible to use return error in the helpers that formulas use. Helpers only can use throw and assert.

To try to fix both issues, a first proposal was made in this PR #6089:

  • We fixed the heavy performance cost by avoiding creating errors based on native JS errors.
  • We unified error handling into a single method: using assert.

After that proposal, it was decided that we want to maximize performance even if it means giving up unification. So we chose to return errors instead of throwing/asserting where possible (in the compute functions), and we keep throwing/asserting in the helper functions.

Now, the question you raise is interesting. Since there are only about thirty assert calls left in the helpers, maybe we could replace them with throw. I can do that in another commit but this is becoming nitpicking (IMO)

@laa-odoo
Copy link
Collaborator Author

laa-odoo commented May 2, 2025

@rrahir Thanks for comments on the commit message :)

@laa-odoo laa-odoo force-pushed the master-formula-function-ref-assert-and-errors-laa branch from bff4dac to 13a43cc Compare May 2, 2025 10:58
@LucasLefevre LucasLefevre force-pushed the master-formula-function-ref-assert-and-errors-laa branch from 13a43cc to 2bde477 Compare May 6, 2025 12:25
Comment on lines 35 to 38
if (args.some((arg) => Array.isArray(arg) && (arg.length !== 1 || arg[0].length !== 1))) {
throw new EvaluationError(errorStr);
return false;
}
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !args.some((arg) => Array.isArray(arg) && (arg.length !== 1 || arg[0].length !== 1))

For performance reasons:
- in compute functions, replace asserts with return errors
- in asserts, replace lambda condition by normal condition

Initially, the compute time spent handling errors in formulas was unusually
high.
This happened mainly for two reasons:

- Creating errors from native JavaScript errors is very costly.
- Throwing errors is also costly (but still less than the first point).

At the same time, we had a unification problem: in all the code that implements
formulas, we had several ways to handle errors:

- Using throw with the error we want
- Using return with the error we want
- Using assert, which throws specific errors (more elegant than a simple throw
  after a condition)

Note that there is also a technical constraint: it is not possible to use return
error in the helpers that formulas use. Helpers only can use throw and assert.

To try to fix both issues, a first proposal was made in this PR #6089:

We fixed the heavy performance cost by avoiding creating errors based on native
JS errors.
We unified error handling into a single method: using assert.
After that proposal, it was decided that we want to maximize performance even
if it means giving up unification. So we chose to return errors instead of
throwing/asserting where possible (in the compute functions), and we keep
throwing/asserting in the helper functions.

Co-authored-by: Anthony Hendrickx (anhe) <[email protected]>
Task: 4760596
@LucasLefevre LucasLefevre force-pushed the master-formula-function-ref-assert-and-errors-laa branch from 2bde477 to 5dd6bec Compare May 6, 2025 13:27
@LucasLefevre
Copy link
Collaborator

robodoo r+

robodoo pushed a commit that referenced this pull request May 6, 2025
For performance reasons:
- in compute functions, replace asserts with return errors
- in asserts, replace lambda condition by normal condition

Initially, the compute time spent handling errors in formulas was unusually
high.
This happened mainly for two reasons:

- Creating errors from native JavaScript errors is very costly.
- Throwing errors is also costly (but still less than the first point).

At the same time, we had a unification problem: in all the code that implements
formulas, we had several ways to handle errors:

- Using throw with the error we want
- Using return with the error we want
- Using assert, which throws specific errors (more elegant than a simple throw
  after a condition)

Note that there is also a technical constraint: it is not possible to use return
error in the helpers that formulas use. Helpers only can use throw and assert.

To try to fix both issues, a first proposal was made in this PR #6089:

We fixed the heavy performance cost by avoiding creating errors based on native
JS errors.
We unified error handling into a single method: using assert.
After that proposal, it was decided that we want to maximize performance even
if it means giving up unification. So we chose to return errors instead of
throwing/asserting where possible (in the compute functions), and we keep
throwing/asserting in the helper functions.

closes #6248

Task: 4760596
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Co-authored-by: Anthony Hendrickx (anhe) <[email protected]>
@robodoo robodoo added the 18.4 label May 6, 2025
@robodoo robodoo closed this May 6, 2025
@fw-bot fw-bot deleted the master-formula-function-ref-assert-and-errors-laa branch May 13, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants