简体   繁体   中英

F# project is taking so much time to build

I have created f# solution and added one class library. Only one project in the solution and 5 files and 20 lines of code in each file. Still it will take more 2 minutes to build each time.

I have tried to clean solution. Also created new solution and project and includes same files, still it will take same time to build it.

Note : First I have created it as a Console Application then convert it into the Class Library.

Edit: Code Sample `

open System open Configuration open DBUtil open Definitions

module DBAccess =

let GetSeq (sql: string) =
      let db = dbSchema.GetDataContext(connectionString)  
      db.DataContext.CommandTimeout <- 0                        
      (db.DataContext.ExecuteQuery(sql,""))


let GetEmployeeByID (id: EMP_PersonalEmpID) = 
    GetSeq (String.Format("EXEC [EMP_GetEntityById] {0}",id.EmployeeID)) |> Seq.toList<EMP_PersonalOutput>

let GetEmployeeListByIDs (id : Emp_PersonalInput) = 
    GetSeq (String.Format("EXEC [EMP_GetEntityById] {0}",id.EmployeeID)) |> Seq.toList<EMP_PersonalOutput>`

configuration code snippets : `open Microsoft.FSharp.Data.TypeProviders

module Configuration = let connectionString = System.Configuration.ConfigurationManager.ConnectionStrings.["EmpPersonal"].ConnectionString

//for database,then stored procedure, the getting the context,then taking the employee table
type dbSchema =  SqlDataConnection<"", "EmpPersonal">
//let db = dbSchema.GetDataContext(connectionString)

type tbEmpPersonal = dbSchema.ServiceTypes.EMP_Personal`

Okay, seeing your actual code, I think the main problem is that the type provider connects to the database every time to retrieve the schema. The way to fix this is to cache the schema in a dbml file.

type dbSchema = SqlDataConnection<"connection string...",
                                  LocalSchemaFile = "myDb.dbml",
                                  ForceUpdate = false>

The first time, the TP will connect to the database as usual, but it will also write the schema to myDb.dbml . On subsequent compiles, it will load the schema from myDb.dbml instead of connecting to the database.

Of course, this caching means that changes to the database are not reflected in the types. So every time you need to reload the schema from the database, you can set ForceUpdate to true , do a compile (which will connect to the db), and set it back to false to use the updated myDb.dbml .

Edit: you can even commit the dbml file to your source repository if you want. This will have the additional benefit to allow collaborators who don't have access to a development version of the database to compile the solution anyway.

关于NGEN的答案曾经帮助过我一次,但是与C#相比,F#的构建时间仍然很糟糕,而不仅仅是几分钟。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM