Questions tagged [lazy-loading]

For programming questions about "lazy loading", a design pattern that defers initialization of an object until the point at which it is needed.

Lazy loading is a commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. The opposite of lazy loading is Eager Loading.

5366 questions
70
votes
14 answers

Is it bad practice to have my getter method change the stored value?

Is it bad practice to change my getter method like version 2 in my class. Version 1: public String getMyValue(){ return this.myValue } Version 2: public String getMyValue(){ if(this.myValue == null || this.myValue.isEmpty()){ …
someone
  • 6,417
  • 7
  • 33
  • 56
64
votes
4 answers

Doctrine 2 ArrayCollection filter method

Can I filter out results from an arrayCollection in Doctrine 2 while using lazy loading? For example, // users = ArrayCollection with User entities containing an "active" property $customer->users->filter('active' => TRUE)->first() It's unclear for…
Dennis
  • 3,338
  • 8
  • 36
  • 45
64
votes
1 answer

Implicitly lazy static members in Swift

I just noticed that static members of Swift structs are implicitly lazy. For instance, this will only call the init once: class Baz { init(){ print("initializing a Baz") } } struct Foo { static let bar = Baz() } var z =…
cfischer
  • 23,024
  • 36
  • 125
  • 209
62
votes
5 answers

Disable lazy loading by default in Entity Framework 4

It seems that lazy loading is enabled by default in EF4. At least, in my project, I can see that the value of dataContext.ContextOptions.LazyLoadingEnabled is true by default. I don't want lazy loading and I don't want to have to…
Mike Chamberlain
  • 29,972
  • 27
  • 103
  • 151
59
votes
15 answers

Angular2 lazy loading module error 'cannot find module'

I was trying to find any solution for this error but nothing works for me. I have simple Angular2 App created with Angular-CLI. When I serve this app in browser I'm getting this error: EXCEPTION: Uncaught (in promise): Error: Cannot find module…
arthurr
  • 1,075
  • 1
  • 10
  • 19
59
votes
3 answers

Using Glide for Android, how do I load images from asset and resources?

I want to keep all the transformation, stoke and animations identical and was thinking if we can pass resource ID or asset name in Glide to load it locally?
ir2pid
  • 3,650
  • 8
  • 40
  • 75
56
votes
2 answers

lazy loading: progressive vs on-demand

This is a conceptual question. In my particular case, I am using slick.js to create an image carousel for a website. Since these are high resolution photographs, I want to speed up the page load time by allowing the photographs to be loaded…
Caleb Faruki
  • 2,267
  • 3
  • 25
  • 48
55
votes
4 answers

infinite scroll with ember.js (lazy loading)

I have a view where there can be a large number of items for the user to scroll through and I'd like to implement infinite scrolling to enable progressive loading of the content. It looks like some folks have done pagination but Google doesn't…
outside2344
  • 1,959
  • 1
  • 26
  • 50
53
votes
3 answers

How to test whether lazy loaded JPA collection is initialized?

I have a service that gets a JPA entity from outside code. In this service I would like to iterate over a lazily loaded collection that is an attribute of this entity to see if the client has added something to it relative to the current version in…
akira
  • 1,721
  • 2
  • 16
  • 17
52
votes
7 answers

Cached property vs Lazy

In .NET 4 the following snippet with a cached property can also be written using the System.Lazy class. I measured the performance of both approaches and it's pretty much the same. Is there any real benefit or magic for why I should use one over…
Martin Buberl
  • 42,048
  • 25
  • 96
  • 139
51
votes
10 answers

How to Lazy Load div background images

As many of you know it is widely used to lazy load images. Now i want to use this as lazy load div background images. How can i do that ? I am currently able to use http://www.appelsiini.net/projects/lazyload that plugin So i need to modify it in a…
MonsterMMORPG
  • 20,310
  • 69
  • 183
  • 306
49
votes
6 answers

Generate a routing module while creating a module in angular-cli

I recently started implementing lazy loading in my application. I was wondering whether there is any way to create a routing.module.ts while generating a new module in angular-cli application other than creating it manually?
Saiyaff Farouk
  • 3,135
  • 3
  • 22
  • 35
41
votes
4 answers

Repository Pattern: how to Lazy Load? or, Should I split this Aggregate?

I have a domain model that has the concept of an Editor and a Project. An Editor owns a number of Projects, and a Project has not only an Editor owner, but also a number of Editor members. Therefore, an Editor also has a number of "joined"…
40
votes
11 answers

Thread-safe cache of one object in java

let's say we have a CountryList object in our application that should return the list of countries. The loading of countries is a heavy operation, so the list should be cached. Additional requirements: CountryList should be thread-safe CountryList…
Igor Mukhin
  • 13,058
  • 17
  • 48
  • 60
40
votes
3 answers

Hibernate count collection size without initializing

Is there a way I can count the size of an associated collection without initializing? e.g. Select count(p.children) from Parent p (there is a good reason why I cant do this any other way as my where clause is more complicated and my from clause is…
DD.
  • 19,793
  • 49
  • 140
  • 237