Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:40:38+00:00 2026-06-08T12:40:38+00:00

Given a trait containing an object with a large-ish number of instances (100 files,

  • 0

Given a trait containing an object with a large-ish number of instances (100 files, each 100 lines) stored in non-lazy val

trait Repository {
  object dao {
    val a = new A
    val b = new B
    val c = new C
    ...
  }
}

what is the initialization cost? Assume that there are 100 Repository consumers, one per DAO instance (i.e. “object X extends Repository” * 100). Will object X, Y, Z consumers each incur the overhead of 100 DAO instances?

Given that Repository consumers will only ever need to reference a subset of DAO instances, I am thinking of taking the lazy initialization approach instead, but trying to see what the trade off is here between cost of lazy vs. non-lazy initialization.

If, on JVM container startup, all 100 DAO instances are initialized, then a non-lazy approach would avoid the unnecessary overhead of lazy initialization. However, if 100 DAO instances are created for each Repository consumer, better to go lazy and reduce memory usage.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:40:39+00:00Added an answer on June 8, 2026 at 12:40 pm

    As far as I know, objects are lazily initialised. For instance with

    trait Repository {
      object dao {
        val a = { println( "aqui" ); 33 }
      }
    }
    

    Observe:

    val x = new Repository {}  // pasa nada
    

    Only now:

    x.dao // pasa algo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given N SIFT/SURF features extracted from 100 training images describing a specific object, and
Given an instance of a class, we can obviously return its name: trait MixedInClassDiscovery
Given a trait T trait T { def v: Int def +(t: T): T
Trait Traversable has methods such as toList , toMap , ToSeq . Given that
Given the following: trait Fruit class Apple extends Fruit class Orange extends Fruit case
I am using an API where a trait is given like this: package pkg
Given the following code: class A { class B type C <: B trait
Given this code: trait S { def s: String } trait I { def
Given a Map[String, Int] in Scala, I want to create a trait that allows
Given that the web application doesn't have su privileges, I'd like to execute a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.