Skip to content

Commit

Permalink
Don't search for the extends relation on functions in Python
Browse files Browse the repository at this point in the history
Summary:
The current implementation of this is a manuall search to great depth and is extremely expensive. from D45096125
So much so it breaks CodeHub API Docs and the `describe()` method in glass having O(1) properties for finding parents.

The extends relation has to be a lookup at depth 1. If it isn't, re-index the content until it is.

Removing this branch now so that things aren't borked.

Note: I'm not removing the ability to find python overrides in general, just the use of this in the `extends` relation in search related, which specifically expects it to be O(1) at depth =1 (i.e. limit=1 from glass). that's used in Glass::describe() which has to be very cheap.

I suspect this is behind the long lurking comments that Python API pages don't load: the extends relation for both child and parent often run to 15s _per method_

https://fburl.com/scuba/glean_server/lc0k4idz

Main issue: 8s to fail to find a method override:
```
fbsource.fbcode.python> F = python.FunctionDeclaration { name = "libfb.py.fb_record.model.Model.is_sharded" }; python.MethodOverriden { base = F }

0 results, 0 facts, 8423.35ms, 8138216 bytes, 25489 compiled bytes
Facts searched:
                    python.NameToSName.4 : 269056
                          python.SName.4 : 269055
                       python.Contains.4 : 1993
             python.BaseClassToDerived.4 : 1630
            python.FunctionDeclaration.4 : 1
             python.FunctionDefinition.4 : 1
                           python.Name.4 : 1
```

FOR NOW: disable this. Come back with a function -> function lookup table for it.

Reviewed By: pepeiborra

Differential Revision: D62227257

fbshipit-source-id: 46054210dddeba55397dc3933ccfeef184601e7d
  • Loading branch information
donsbot authored and facebook-github-bot committed Sep 5, 2024
1 parent 56d9fee commit 9d55822
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
{
"@generated": null,
"python.BaseClassToDerived.4": 4,
"python.ClassDeclaration.4": 9,
"python.FunctionDeclaration.4": 14,
"python.FunctionDefinition.4": 13,
"python.NameToSName.4": 6
}
{ "@generated": null, "python.BaseClassToDerived.4": 4 }
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
{
"@generated": null,
"python.ClassDeclaration.4": 9,
"python.ClassDefinition.4": 13,
"python.FunctionDeclaration.4": 14,
"python.FunctionDefinition.4": 13,
"python.NameToSName.4": 6
}
{ "@generated": null, "python.ClassDefinition.4": 7 }
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"@generated": null,
"python.BaseClassToDerived.4": 4,
"python.ClassDeclaration.4": 11,
"python.ClassDeclaration.4": 2,
"python.DeclarationDefinition.4": 6,
"python.DeclarationLocation.4": 7,
"python.FunctionDeclaration.4": 14,
"python.FunctionDefinition.4": 13,
"python.ImportStatementByAsName.4": 1,
"python.NameToSName.4": 6
"python.ImportStatementByAsName.4": 1
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"@generated": null,
"python.ClassDeclaration.4": 11,
"python.ClassDefinition.4": 13,
"python.ClassDeclaration.4": 2,
"python.ClassDefinition.4": 7,
"python.DeclarationDefinition.4": 6,
"python.DeclarationLocation.4": 7,
"python.FunctionDeclaration.4": 14,
"python.FunctionDefinition.4": 13,
"python.ImportStatementByAsName.4": 1,
"python.NameToSName.4": 6
"python.ImportStatementByAsName.4": 1
}
25 changes: 6 additions & 19 deletions glean/schema/source/codemarkup.python.angle
Original file line number Diff line number Diff line change
Expand Up @@ -257,32 +257,19 @@ predicate PythonExtendsParentEntity :
parent : code.python.Entity
}
{ Child, Parent } where
(
{ decl = { cls = ChildClassDecl } } = Child;
python.DerivedClassToBase { ChildClassDecl, ParentClassDecl };
{ decl = { cls = ParentClassDecl } } = Parent;
) | (
{ decl = { func = ChildMethodDecl } } = Child;
python.MethodOverrides { ChildMethodDecl, ParentMethodDecl};
{ decl = { func = ParentMethodDecl } } = Parent;
)

{ decl = { cls = ChildClassDecl } } = Child;
python.DerivedClassToBase { ChildClassDecl, ParentClassDecl };
{ decl = { cls = ParentClassDecl } } = Parent;

predicate PythonExtendsChildEntity :
{
parent: code.python.Entity,
child: code.python.Entity
}
{ Parent, Child } where
(
{ decl = {cls = ParentClassDecl} } = Parent;
python.BaseClassToDerived { base = ParentClassDecl, derived = ChildClassDecl };
{ decl = { cls = ChildClassDecl } } = Child;
) | (
{ decl = { func = ParentMethodDecl} } = Parent;
python.MethodOverriden { ParentMethodDecl, ChildMethodDecl };
{ decl = { func = ChildMethodDecl } } = Child;
)
{ decl = {cls = ParentClassDecl} } = Parent;
python.BaseClassToDerived { base = ParentClassDecl, derived = ChildClassDecl };
{ decl = { cls = ChildClassDecl } } = Child;

predicate PythonEntityModuleName :
{
Expand Down

0 comments on commit 9d55822

Please sign in to comment.