Require some insight regarding Objects & Json

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Require some insight regarding Objects & Json

Prakhar Makhija
Hi,


*Scenario*

Having 1.5 million json files of same structure (same keys).
Each file is of around 64 KB, which makes a total of 1 GB.

Created a class MyDummyJsonClass, having the attribute names same as the
keys in those json files.

Reading the json files, loading them into MyDummyJsonClass, using
ObjectMapper.


*Doubt 1*

Will the objects occupy the same amount of space in Java's Memory, as they
were occupying earlier as flat files?


*Doubt 2*

Does Java convert Objects to Enumerations at Runtime?

What I mean to ask is, does it enumerate the attribute names while creating
objects, in order to save the memory?

Because the Class is just a blueprint, and we create objects out of it over
and over again.


*Example*


class MyDummyJsonClass {

private Object meaningfulNameOfAttributeOne;
private String meaningfulNameOfAttributeTwo;
private Integer meaningfulNameOfAttributeThree;
private Float meaningfulNameOfAttributeFour;
private Double meaningfulNameOfAttributeFive;
private Long meaningfulNameOfAttributeSix;
private Byte meaningfulNameOfAttributeSeven;
private Boolean meaningfulNameOfAttributeEight;
private Character meaningfulNameOfAttributeNine;
private Short meaningfulNameOfAttributeTen;

// Contructors

// Getters & Setters

}


Here the field meaningfulNameOfAttributeOne is of 28 characters, and Java
uses Unicode, so internally just this attribute name will it be occupying
56 bytes of memory in every Object we create?

Or is meaningfulNameOfAttributeOne mapped to enum value 1, and will occupy
maybe just 1 byte, depending upon the number of fields?

If less than or equal to 256 fields in the class, allocate 1 byte enum,
else 2 bytes enum.

And some kind of Interceptor decides, to give it logical attribute name
mapping?
Reply | Threaded
Open this post in threaded view
|

Re: Require some insight regarding Objects & Json

Bernd Eckenfels-4
Hello,

the Java Objects will occupy more (especially If the Parser does not provide a way to merge same-string-content objects.

It depends on the Parser what is converted (but I am not Aware of any which Support Enumerations out of the box, especially since JSON-P JSR is limited to generic (DOM-like) objects)

I also think the list here is a bit offtopic for such a question, what JSON-Parser do you plan to use?

Gruss
Bernd
--
http://bernd.eckenfels.net

Von: Prakhar Makhija
Gesendet: Sonntag, 12. November 2017 18:57
An: [hidden email]; [hidden email]
Betreff: Require some insight regarding Objects & Json

Hi,


*Scenario*

Having 1.5 million json files of same structure (same keys).
Each file is of around 64 KB, which makes a total of 1 GB.

Created a class MyDummyJsonClass, having the attribute names same as the
keys in those json files.

Reading the json files, loading them into MyDummyJsonClass, using
ObjectMapper.


*Doubt 1*

Will the objects occupy the same amount of space in Java's Memory, as they
were occupying earlier as flat files?


*Doubt 2*

Does Java convert Objects to Enumerations at Runtime?

What I mean to ask is, does it enumerate the attribute names while creating
objects, in order to save the memory?

Because the Class is just a blueprint, and we create objects out of it over
and over again.


*Example*


class MyDummyJsonClass {

private Object meaningfulNameOfAttributeOne;
private String meaningfulNameOfAttributeTwo;
private Integer meaningfulNameOfAttributeThree;
private Float meaningfulNameOfAttributeFour;
private Double meaningfulNameOfAttributeFive;
private Long meaningfulNameOfAttributeSix;
private Byte meaningfulNameOfAttributeSeven;
private Boolean meaningfulNameOfAttributeEight;
private Character meaningfulNameOfAttributeNine;
private Short meaningfulNameOfAttributeTen;

// Contructors

// Getters & Setters

}


Here the field meaningfulNameOfAttributeOne is of 28 characters, and Java
uses Unicode, so internally just this attribute name will it be occupying
56 bytes of memory in every Object we create?

Or is meaningfulNameOfAttributeOne mapped to enum value 1, and will occupy
maybe just 1 byte, depending upon the number of fields?

If less than or equal to 256 fields in the class, allocate 1 byte enum,
else 2 bytes enum.

And some kind of Interceptor decides, to give it logical attribute name
mapping?

Reply | Threaded
Open this post in threaded view
|

Re: Require some insight regarding Objects & Json

Prakhar Makhija
In reply to this post by Prakhar Makhija
Corrections :


*Scenario*

Have 1.5 billion json files, Each file is of around 655 bytes, which makes
a total of around 937.5 MB.


*Example*

Or is meaningfulNameOfAttributeOne internally mapped to enum value 0, and
will occupy maybe just 1 byte, depending upon the number of fields?


On Sun, Nov 12, 2017 at 9:56 PM, Prakhar Makhija <[hidden email]> wrote:

> Hi,
>
>
> *Scenario*
>
> Having 1.5 million json files of same structure (same keys).
> Each file is of around 64 KB, which makes a total of 1 GB.
>
> Created a class MyDummyJsonClass, having the attribute names same as the
> keys in those json files.
>
> Reading the json files, loading them into MyDummyJsonClass, using
> ObjectMapper.
>
>
> *Doubt 1*
>
> Will the objects occupy the same amount of space in Java's Memory, as they
> were occupying earlier as flat files?
>
>
> *Doubt 2*
>
> Does Java convert Objects to Enumerations at Runtime?
>
> What I mean to ask is, does it enumerate the attribute names while
> creating objects, in order to save the memory?
>
> Because the Class is just a blueprint, and we create objects out of it
> over and over again.
>
>
> *Example*
>
>
> class MyDummyJsonClass {
>
> private Object meaningfulNameOfAttributeOne;
> private String meaningfulNameOfAttributeTwo;
> private Integer meaningfulNameOfAttributeThree;
> private Float meaningfulNameOfAttributeFour;
> private Double meaningfulNameOfAttributeFive;
> private Long meaningfulNameOfAttributeSix;
> private Byte meaningfulNameOfAttributeSeven;
> private Boolean meaningfulNameOfAttributeEight;
> private Character meaningfulNameOfAttributeNine;
> private Short meaningfulNameOfAttributeTen;
>
> // Contructors
>
> // Getters & Setters
>
> }
>
>
> Here the field meaningfulNameOfAttributeOne is of 28 characters, and Java
> uses Unicode, so internally just this attribute name will it be occupying
> 56 bytes of memory in every Object we create?
>
> Or is meaningfulNameOfAttributeOne mapped to enum value 1, and will
> occupy maybe just 1 byte, depending upon the number of fields?
>
> If less than or equal to 256 fields in the class, allocate 1 byte enum,
> else 2 bytes enum.
>
> And some kind of Interceptor decides, to give it logical attribute name
> mapping?
>
>