Verified Commit 956cbd5d authored by Camil Staps's avatar Camil Staps 🙂

Performance enhancements

- Adapt to performance enhancements in Database.Native returning [!!]
  from getEntries
- Add type_synonyms index array to avoid walking through entire database
  on unification queries
parent 05998593
......@@ -3,7 +3,11 @@ definition module Cloogle.DB
from StdOverloaded import class ==, class <, class zero
from StdClass import class Ord
from Clean.Types import :: Unifier
from Clean.Types import :: Type, :: TypeVar, :: TVAssignment, :: TypeDef,
:: TypeContext, :: TypeDefRhs, :: TypeRestriction, :: Priority, :: Unifier
from Clean.Types.Tree import :: TypeTree
from Clean.Types.Util import class print(..)
from Data.GenEq import generic gEq
from Data.Map import :: Map
from Data.Maybe import :: Maybe
......@@ -14,11 +18,6 @@ from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from Regex import :: Regex
from Clean.Types import :: Type, :: TypeVar, :: TVAssignment, :: TypeDef,
:: TypeContext, :: TypeRestriction, :: Priority
from Clean.Types.Tree import :: TypeTree
from Clean.Types.Util import class print(..)
from Clean.Doc import :: FunctionDoc, :: TypeDoc, :: ClassDoc, :: ModuleDoc
from Cloogle.API import :: FunctionKind, :: SyntaxExample,
......@@ -40,6 +39,7 @@ NGRAMS_CI :== True
, builtins :: !{#Index} //* Entries in Clean core
, syntax :: !{#Index} //* SyntaxEntries
, abc_instrs :: !{#Index} //* ABCInstructionEntries
, type_synonyms :: !{#Index} //* TypeDefEntries of TDRSynonym
, library_map :: !Map Name {#Index} //* Entries by library name
, module_map :: !Map Name {#Index} //* Entries by module name
, derive_map :: !Map Name {#Index} //* DeriveEntries by generic name
......@@ -237,6 +237,7 @@ isBuiltin :: !Location -> Bool
toTypeDefEntry :: !Location !TypeDef !(Maybe TypeDoc) -> TypeDefEntry
getTypeDef :: !TypeDefEntry -> TypeDef
getTypeDefRhs :: !TypeDefEntry -> TypeDefRhs
getTypeDefDoc :: !TypeDefEntry -> Maybe TypeDoc
mergeTypeDefEntries :: !TypeDefEntry !TypeDefEntry -> TypeDefEntry
......@@ -297,4 +298,4 @@ getDerivations :: !Name !*CloogleDB -> *([DeriveEntry], *CloogleDB)
*/
removeContainedEntries :: !*CloogleDB -> *CloogleDB
getEntries :: !*CloogleDB -> *([(CloogleEntry, [Annotation])], *CloogleDB)
getEntries :: !*CloogleDB -> *([!(CloogleEntry, [Annotation])!], *CloogleDB)
implementation module Cloogle.DB
// Standard libraries
import _SystemStrictLists
import StdArray
import StdBool
import StdFile
......@@ -196,6 +196,9 @@ toTypeDefEntry loc td doc =
getTypeDef :: !TypeDefEntry -> TypeDef
getTypeDef {tde_typedef} = tde_typedef
getTypeDefRhs :: !TypeDefEntry -> TypeDefRhs
getTypeDefRhs {tde_typedef} = tde_typedef.td_rhs
getTypeDefDoc :: !TypeDefEntry -> Maybe TypeDoc
getTypeDefDoc {tde_doc} = tde_doc
......@@ -223,7 +226,8 @@ classContext ce = ce.ce_context
saveDB :: !*CloogleDB !*File -> *(!*CloogleDB, !*File)
saveDB wrapper=:{db,name_ngrams,name_map,types,core,apps,builtins,syntax,
abc_instrs,library_map,module_map,derive_map,instance_map,always_unique} f
abc_instrs,type_synonyms,library_map,module_map,derive_map,instance_map,
always_unique} f
# (db,f) = 'Database.Native'.saveDB db f
# f = write name_ngrams f
# f = write name_map f
......@@ -233,6 +237,7 @@ saveDB wrapper=:{db,name_ngrams,name_map,types,core,apps,builtins,syntax,
# f = write builtins f
# f = write syntax f
# f = write abc_instrs f
# f = write type_synonyms f
# f = write library_map f
# f = write module_map f
# f = write derive_map f
......@@ -255,6 +260,7 @@ openDB f
# (builtins,f) = read f
# (syntax,f) = read f
# (abc_instrs,f) = read f
# (type_synonyms,f) = read f
# (library_map,f) = read f
# (module_map,f) = read f
# (derive_map,f) = read f
......@@ -269,6 +275,7 @@ openDB f
builtins >>= \builtins ->
syntax >>= \syntax ->
abc_instrs >>= \abc_instrs ->
type_synonyms >>= \type_synonyms ->
library_map >>= \library_map ->
module_map >>= \module_map ->
derive_map >>= \derive_map ->
......@@ -283,6 +290,7 @@ openDB f
, builtins=builtins
, syntax=syntax
, abc_instrs=abc_instrs
, type_synonyms=type_synonyms
, library_map=library_map
, module_map=module_map
, derive_map=derive_map
......@@ -499,13 +507,13 @@ where
| otherwise = ['Database.Native'.Index i:mergeIntersect is js]
allTypeSynonyms :: !*CloogleDB -> *(Map Name [TypeDef], *CloogleDB)
allTypeSynonyms wrap=:{db}
# (es,db) = 'Database.Native'.allEntries db
allTypeSynonyms wrap=:{db,type_synonyms}
# (es,db) = 'Database.Native'.getIndices` type_synonyms db
= (fromList
$ map collect
$ groupBy ((==) `on` fst)
$ sortBy ((<) `on` fst)
[(td.td_name, td) \\ TypeDefEntry {tde_typedef=td=:{td_rhs=TDRSynonym t}} <- es]
[(td.td_name, td) \\ {value=TypeDefEntry {tde_typedef=td=:{td_rhs=TDRSynonym t}}} <|- es]
, {wrap & db=db}
)
where
......@@ -564,7 +572,7 @@ where
updateAnnots [a=:UsedSynonyms _:as] m = updateAnnots as [a:[a \\ a <- m | not (a=:UsedSynonyms _)]]
updateAnnots [a=:RequiredContext _:as] m = updateAnnots as [a:[a \\ a <- m | not (a=:RequiredContext _)]]
getEntries :: !*CloogleDB -> *([(CloogleEntry, [Annotation])], *CloogleDB)
getEntries :: !*CloogleDB -> *([!(CloogleEntry, [Annotation])!], *CloogleDB)
getEntries wrap=:{db}
# (es,db) = 'Database.Native'.getEntries db
= (es, {wrap & db=db})
......@@ -177,6 +177,9 @@ finaliseDB extra tdb =
, builtins = idxarr \e -> fromMaybe False ('Cloogle.DB'.isBuiltin <$> 'Cloogle.DB'.getLocation e)
, syntax = idxarr \e -> e=:(SyntaxEntry _)
, abc_instrs = idxarr \e -> e=:(ABCInstructionEntry _)
, type_synonyms = idxarr \e -> case e of
TypeDefEntry tde -> ('Cloogle.DB'.getTypeDefRhs tde)=:('Clean.Types'.TDRSynonym _)
_ -> False
, library_map = libmap
, module_map = modmap
, derive_map = 'Data.Map'.fromList
......
......@@ -34,13 +34,13 @@ DEFAULT_INCLUDE_APPS :== False
/**
* Search for a request in the type database
*/
search :: !Request !*CloogleDB -> *([Result], *CloogleDB)
search :: !Request !*CloogleDB -> *(![Result], !*CloogleDB)
search` :: !Request !*CloogleDB ->
*(!Maybe Type
, !(Map String [TypeDef])
, ![TypeDef]
, ![(!CloogleEntry, ![Annotation])]
, ![!(!CloogleEntry, ![Annotation])!]
, !*CloogleDB
)
......@@ -51,4 +51,4 @@ unifyInformation :: !(Maybe Type) !(Map String [TypeDef]) ![TypeDef] !FunctionEn
* Search for a request, and also make suggestions for similar requests with
* better results.
*/
searchWithSuggestions :: !Request !*CloogleDB -> *([Result], [(Request,[Result])], *CloogleDB)
searchWithSuggestions :: !Request !*CloogleDB -> *(![Result], ![(Request,[Result])], !*CloogleDB)
......@@ -6,6 +6,7 @@ from StdFunc import const, id, flip, o
import StdList
import StdMisc
import StdOrdList
import StdOverloadedList
import StdString
import StdTuple
......@@ -55,17 +56,17 @@ searchStrategy (SSClassName n) db = filterDB (\ce->ce=:(ClassEntry _)) $ filterE
searchStrategy (SSUsing f ns) db = filterUsages f ns db
searchStrategy (SSAnd a b) db = searchStrategy b $ searchStrategy a db
search :: !Request !*CloogleDB -> *([Result], *CloogleDB)
search :: !Request !*CloogleDB -> *(![Result], !*CloogleDB)
search req cdb
# (mbType,allsyns,usedsyns,entries,cdb) = search` req cdb
# (es,cdb) = mapSt (makeResult mbType allsyns usedsyns) entries cdb
= (sort $ catMaybes es, cdb)
# (es,cdb) = mapSt (makeResult mbType allsyns usedsyns) [e \\ e <|- entries] cdb
= (sort [e \\ Just e <- es], cdb)
search` :: !Request !*CloogleDB ->
*(!Maybe Type
, !(Map String [TypeDef])
, ![TypeDef]
, ![(!CloogleEntry, ![Annotation])]
, ![!(!CloogleEntry, ![Annotation])!]
, !*CloogleDB
)
search` {unify,name,className,typeName,using,modules,libraries,page,include_builtins,include_core,include_apps} cdb
......@@ -321,7 +322,7 @@ where
_ -> Nothing
}
searchWithSuggestions :: !Request !*CloogleDB -> *([Result], [(Request,[Result])], *CloogleDB)
searchWithSuggestions :: !Request !*CloogleDB -> *(![Result], ![(Request,[Result])], !*CloogleDB)
searchWithSuggestions req db
# (res,db) = search req db
# (suggs,db) = suggestions req res db
......
......@@ -5,6 +5,7 @@ import StdBool
import StdInt
import StdList
import StdMisc
import StdOverloadedList
import StdReal
import StdString
......@@ -203,7 +204,7 @@ instance < Request where < a b = (gLexOrd{|*|} a b)=:'Data.GenLexOrd'.LT
findConstraints ::
![(Request, RankConstraint)]
!(Map Request (!Maybe Type,!Map String [TypeDef],![TypeDef],![(!CloogleEntry,![Annotation])]))
!(Map Request (!Maybe Type,!Map String [TypeDef],![TypeDef],![!(!CloogleEntry,![Annotation])!]))
!*CloogleDB -> *([String], *CloogleDB)
findConstraints [(req,LT urid1 urid2):rest] results cdb
# (orgsearchtype,allsyns,usedsyns,entries,cdb) = case 'Data.Map'.get req results of
......@@ -220,17 +221,17 @@ findConstraints [(req,LT urid1 urid2):rest] results cdb
= ([this:rest],cdb)
where
findEntry orgsearchtype allsyns usedsyns urid=:(_,mod,name) entries cdb
= case filter (\(e,_) -> match urid e) entries of
[(e1=:FunctionEntry fe,annots):[]]
= case Filter (\(e,_) -> match urid e) entries of
[|(e1=:FunctionEntry fe,annots):[|]]
# (unif,usedsyns,required_context,cdb) = unifyInformation orgsearchtype allsyns usedsyns fe cdb
# annots = [RequiredContext required_context,UsedSynonyms (length usedsyns):annots]
# annots = case unif of
Just unif -> [Unifier unif:annots]
Nothing -> annots
-> (e1,annots,cdb)
[(e1,annots):[]]
[|(e1,annots):[|]]
-> (e1,annots,cdb)
[] -> abort ("no match for URID " +++ mod +++ "." +++ name +++ "\n")
[|] -> abort ("no match for URID " +++ mod +++ "." +++ name +++ "\n")
_ -> abort ("too many matches for URID " +++ mod +++ "." +++ name +++ "\n")
formula :: !RankInformation -> String
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment