Skip to Main Content
  • Questions
  • Mized size of packages causes inefficiency?

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Owen.

Asked: June 06, 2002 - 9:51 am UTC

Last updated: April 07, 2004 - 8:49 am UTC

Version: 8.1.7

Viewed 1000+ times

You Asked

Hi

Until recently I worked at a company where the policy was to have packages matched for size, that is, as far as possible all packages were to be as close as possible to the same, maximum size. This was alleged to improve performance by reducing memory fragmentation. (Note that a consequence of this was that routines were essentially grouped randomly throughout the set of packages, and not by any idea of common function or such-like.)

I couldn't find any evidence to support this policy, nor was any ever provided, but it was the policy nonetheless. Could you shed some light on it for me? Is it a sensible but little-known technique, or just misguided?

Thanks in advance

Owen Phelps

and Tom said...

Sounds like a new myth to me. I've never heard of such a thing.

Besides, a 1,000 line package might compile to be less p-code then a 100 line package.

The fact is -- we page in code in 4k'ish chunks, regardless of size. Once upon a time, many many versions ago, we paged in entire packages/procedures -- for many years now, that has not been the case.

So, it is a myth with a kernel of (old) truth behind it -- but an "unachievable" myth. Were the developers supposed to sit there and add/remove code until the compiled code_size was "right on"??? Impossible, totally impossible.

Totally "non-sensible" and hopefully an almost unknown 'technique'

Reminds me of my Ada programming days. Someone tried to make me ALPHABETIZE my subroutines -- declare them in order alphabetically, define them in order -- alphabetically. They didn't like to read code on "screen", they wanted to print it out to read it and it would help them find stuff (since they couldn't "search" the paper). The end result - I wrote a script to rename all of my routines to:

aa_some_function;
ab_another_function;
ac_......

and so on (and used a big "pragma renames" at the bottom so I didn't have to hack the rest of the code, sort of like a synonym for a procedure). Met the letter of the law, but didn't do anything for anyone.

Here is a query you can use to see that this is totally futile:


1 select trunc(source_size/1024) src_size_k,
2 min(code_size),
3 max(code_size),
4 max(code_size)-min(code_size) diff,
5 count(code_size) cnt
6 from dba_object_size
7 where source_size > 0
8 and type in ( 'PROCEDURE', 'FUNCTION', 'PACKAGE BODY' )
9 group by trunc(source_size/1024)
10 having max(code_size)-min(code_size) > 0
11* order by 4
ops$tkyte@ORA817DEV.US.ORACLE.COM> /

SRC_SIZE_K MIN(CODE_SIZE) MAX(CODE_SIZE) DIFF CNT
---------- -------------- -------------- ---------- ----------
68 16006 16492 486 2
21 6187 6722 535 3
24 6120 6738 618 2
12 1867 2627 760 3
28 5684 6994 1310 2
74 17689 19007 1318 3
20 4954 6555 1601 2
26 4135 6074 1939 3
18 3170 5187 2017 3
150 30077 32203 2126 2
0 149 2383 2234 65
1 0 2239 2239 19
67 15850 18342 2492 2
9 1450 4582 3132 5
10 3191 6597 3406 3
31 6554 9987 3433 3
16 1469 5034 3565 7
27 5006 8935 3929 2
2 331 4375 4044 9
4 268 4549 4281 4
3 1502 5919 4417 2
132 34193 38985 4792 2
5 594 5520 4926 8
122 25256 31011 5755 2
6 1604 8053 6449 5
47 6113 12649 6536 2
11 2736 9588 6852 3
7 1135 9943 8808 4
15 4680 16379 11699 2
13 3321 15039 11718 4
22 3289 16350 13061 7
32 21828 35886 14058 2
54 15473 30590 15117 2
8 2671 17999 15328 5
25 4652 21423 16771 3
23 5379 22723 17344 3
38 8972 26923 17951 2
34 6352 24784 18432 2
17 3951 24080 20129 3
45 10423 44512 34089 3
71 8215 57543 49328 3

41 rows selected.

So, for example, there is some code out there that is 71k in size. The smallest results in about 8k of p-code, the largest in about 57k. Hmmm, what would they do then???


Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

I love those demystifications !!!

Andre, June 06, 2002 - 1:23 pm UTC

I get "mystified" at how people think up such stuff. Have I told you about a former (luckily) boss of mine, a "senior" DBA, who asked me to reduce the number of free-lists because they were taking up too much space ? Yep, believe me, it's the naked truth...

Tom Kyte
June 06, 2002 - 5:43 pm UTC

Well, there is a nuggest of truth in there as well.

A session is associated with a freelist. If you have 10 freelists and a single session doing inserts -- it'll only use one of the freelists -- the others will not be used. We'll grab a new extent without considering the existing freespace that is there.

So the freelists don't take up space really -- but they can lead to "less efficient space utilization" if you have way more then you really need. (stress CAN -- eg might -- eg don't worry about it 99.999% of the time)

Great, thanks.

Owen, June 06, 2002 - 2:25 pm UTC

That's much what I had expected, but it's great to have it confirmed. Thanks very much!

continued

Andre, June 07, 2002 - 3:05 pm UTC

Thanks for the feedback on the freelist stuff. In fact I had heard of it and it makes sense, but surely it wasn't the case with my boss. As a matter of fact he had no idea what a free list was all about...

Package size

mani, March 23, 2004 - 12:39 pm UTC

Hi Tom,
We provide software services to our clients. One of the modules is reporting.
Currently we have created one package for each client.
Each package can have 15 to 20 huge procedures ( approx 150 lines each procedure ). Each procedure relates to custom report.
1) A client user may just request one report, in this case since the report procedure is in package, does the entire package get loaded in memory ( I know 4K chunks ).
That means extra 4K chunks are allocated , where in first place get could be avioded.
2) I know you say its common sense to group procedures in packages, does this mean only dependent procedures or procedures which belong to one transaction be put in one package.
3) In my case the Client wise package is a business wise logical package , but since client users may call reports independently the procedures doesn't seem to be logically
bound in terms of database angle.
4) When a procedure ( in a package ) is called , does oracle load the entire package in memory or just that procedure.

Please advice,
Mani

Tom Kyte
March 23, 2004 - 5:31 pm UTC

loads by piece, but 150 lines is hardly "huge".

use the package to make your life "easier", do what makes most sense from a programming point of view.

Mixed Sizes of Packages causes inefficiency?

Steve Booth, April 06, 2004 - 5:00 pm UTC

Hope you're having a good vacation. Thanks for the info regarding package sizes. If you wouldn't mind, do you have any rule of thumb regarding overall sizes of packages? What's too big? Does "Debug" make much of a difference? I used a compile command without seeing any change so I probably screwed it up.

I had been looking for where I could find out package sizes. Thanks again!

Tom Kyte
April 07, 2004 - 8:49 am UTC

packages (plsql) is paged in in pieces. the overall sizes do not matter, they are all managed in about 4k chunks.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library